Skip to content

Update the CS1031 page #47527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 26 additions & 29 deletions docs/csharp/misc/cs1031.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,32 @@ ms.assetid: 14196659-aaac-4df2-a4ed-0bebb8097d59

Type expected

A type parameter is expected.
## Example
A type has not been specified where expected, when [overloading an operator](../language-reference/operators/operator-overloading.md).
<br/>Missing *type* in this case means that there's no *type* given for the return type of the overloaded operator.
This error shouldn't be confused with missing [generic type parameter](../../csharp/programming-guide/generics/generic-type-parameters.md).

The following sample generates CS1031:

```csharp
// CS1031.cs
namespace x
{
public class ii
{
}

public class a
## Example

The following sample generates CS1031:

```csharp
namespace x
{
public class I
{
}

public class A
{
public static operator +(a aa) // CS1031
// try the following line instead
// public static ii operator +(a aa)
{
return new ii();
}

public static void Main()
{
e = new base; // CS1031, not a type
e = new this; // CS1031, not a type
e = new (); // CS1031, not a type
}
}
}
public static operator +(A a) // CS1031 - Overloaded operator missing a type
{
return new I();
}

public static I operator +(A a) // Correct - type was specified
{
return new I();
}
}
}
```