Reputation: 10171
This is possible to have a property and a event with the same name in a class for example:
private BusyChangedDelegate BusyChanged;
public event BusyChangedDelegate BusyChanged
{
.
.
.
}
Edit Complete source
private BusyChangedDelegate BusyChanged;
public event BusyChangedDelegate BusyChanged
{
add
{
BusyChangedDelegate delegate3;
BusyChangedDelegate busyChanged = this.BusyChanged;
do
{
delegate3 = busyChanged;
BusyChangedDelegate delegate4 = (BusyChangedDelegate) Delegate.Combine(delegate3, value);
busyChanged = Interlocked.CompareExchange<BusyChangedDelegate>(ref this.BusyChanged, delegate4, delegate3);
}
while (busyChanged != delegate3);
}
remove
{
BusyChangedDelegate delegate3;
BusyChangedDelegate busyChanged = this.BusyChanged;
do
{
delegate3 = busyChanged;
BusyChangedDelegate delegate4 = (BusyChangedDelegate) Delegate.Remove(delegate3, value);
busyChanged = Interlocked.CompareExchange<BusyChangedDelegate>(ref this.BusyChanged, delegate4, delegate3);
}
while (busyChanged != delegate3);
}
}
Upvotes: 1
Views: 405
Reputation: 1503080
No. A class can't declare two members with the same name, other than for method overloading.
Just change your variable name to be camelCased, which follows the normal conventions anyway...
private BusyChangedDelegate busyChanged;
From section 10.3 of the C# 5 specification:
The name of a constant, field, property, event, or type must differ from the names of all other members declared in the same class.
EDIT: Yes, if you look at the IL generated for a field-like event:
public event EventHandler Foo;
you may see both a field called Foo
and an event called Foo
. That's because IL has different rules to C#. The C# compiler can name the auto-generated field however it wants. (See section 10.8.1 of the C# 4 specification, for example.)
It's still not valid in the C# language to name a field the same way as any other member. The code you have posted is not valid C# - it's the best a decompiler can come up with to represent what the C# compiler has created in IL.
Upvotes: 2