Reputation: 31
I'm struggling to understand why these errors/warnings are occurring the below. Most importantly the error, because it's blocking the compile. I can "fix" the error by following the proposed naming convention in the messages and begin the variables with upper case characters. But I just don't understand why .NET is throwing the error.
Severity | Code | Description | Project | File | Line | Suppression State |
---|---|---|---|---|---|---|
Error | CS0102 | The type 'Class1' already contains a definition for 'add_a' | ClassLibrary1 | ClassLibrary1\Class1.cs | 10 | Active |
Message | IDE1006 | Naming rule violation: These words must begin with upper case characters: add_a | ClassLibrary1 | ClassLibrary1\Class1.cs | 8 | Active |
Message | IDE1006 | Naming rule violation: These words must begin with upper case characters: add_a | ClassLibrary1 | ClassLibrary1\Class1.cs | 8 | Active |
Message | IDE1006 | Naming rule violation: These words must begin with upper case characters: a | ClassLibrary1 | ClassLibrary1\Class1.cs | 10 | Active |
Message | IDE1006 | Naming rule violation: These words must begin with upper case characters: a | ClassLibrary1 | ClassLibrary1\Class1.cs | 10 | Active |
namespace ClassLibrary1
{
public class Class1
{
public event myHandler add_a;
public event myHandler a;
public delegate void myHandler(object sender, EventArgs e);
}
}
Upvotes: 2
Views: 62
Reputation: 31
Copying Charlieface comment, which is the answer.
An event implies internal methods such as add_YourEvent and remove_YourEvent so there is a naming clash.
See the spec with reserved names for events https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/classes#143103-member-names-reserved-for-events
Upvotes: 0