File tree Expand file tree Collapse file tree 1 file changed +26
-29
lines changed Expand file tree Collapse file tree 1 file changed +26
-29
lines changed Original file line number Diff line number Diff line change @@ -12,35 +12,32 @@ ms.assetid: 14196659-aaac-4df2-a4ed-0bebb8097d59
12
12
13
13
Type expected
14
14
15
- A type parameter is expected.
16
-
17
- ## Example
15
+ A type has not been specified where expected, when [ overloading an operator ] ( ../language-reference/operators/operator-overloading.md ) .
16
+ < br />Missing * type * in this case means that there's no * type * given for the return type of the overloaded operator.
17
+ This error shouldn't be confused with missing [ generic type parameter ] ( ../../csharp/programming-guide/generics/generic-type-parameters.md ) .
18
18
19
- The following sample generates CS1031:
20
-
21
- ``` csharp
22
- // CS1031.cs
23
- namespace x
24
- {
25
- public class ii
26
- {
27
- }
28
-
29
- public class a
19
+ ## Example
20
+
21
+ The following sample generates CS1031:
22
+
23
+ ``` csharp
24
+ namespace x
25
+ {
26
+ public class I
27
+ {
28
+ }
29
+
30
+ public class A
30
31
{
31
- public static operator +(a aa) // CS1031
32
- // try the following line instead
33
- // public static ii operator +(a aa)
34
- {
35
- return new ii ();
36
- }
37
-
38
- public static void Main()
39
- {
40
- e = new base; // CS1031, not a type
41
- e = new this; // CS1031, not a type
42
- e = new (); // CS1031, not a type
43
- }
44
- }
45
- }
32
+ public static operator +(A a) // CS1031 - Overloaded operator missing a type
33
+ {
34
+ return new I ();
35
+ }
36
+
37
+ public static I operator +(A a) // Correct - type was specified
38
+ {
39
+ return new I();
40
+ }
41
+ }
42
+ }
46
43
```
You can’t perform that action at this time.
0 commit comments