Skip to content

Commit 89f923a

Browse files
Improve the code example and emphasize on the type parameter
1 parent 9152ee9 commit 89f923a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docs/csharp/misc/cs1031.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 14196659-aaac-4df2-a4ed-0bebb8097d59
1313
Type expected
1414

1515
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).
1618

1719
## Example
1820

@@ -27,11 +29,14 @@ namespace x
2729

2830
public class A
2931
{
30-
public static operator +(A aa) // CS1031
31-
// try the following line instead
32-
// public static ii operator +(a aa)
32+
public static operator +(A a) // CS1031 - Overloaded operator missing a type
3333
{
34-
return new ii();
34+
return new I();
35+
}
36+
37+
public static I operator +(A a) // Correct - type was specified
38+
{
39+
return new I();
3540
}
3641
}
3742
}

0 commit comments

Comments
 (0)