I just came across the above error while I was trying to compile a proxy class generated through svcutil. Here's a short version of the problem:
class A
{
private string colorField;
private string set_colorField;
public string color
{
get
{
return this.colorField;
}
set
{
this.colorField = value;
}
}
public string set_color
{
get
{
return this.set_colorField;
}
set
{
this.set_colorField = value;
}
}
}
This compiles fine:
public string Color
{
get;set;
}
public string Set_Color
{
get;set;
}
But this throws the same error:
public string color
{
get;set;
}
public string set_color
{
get;set;
}
I don't recall ever reading about this restriction. Can someone point me to the relevant section of the C# compiler spec?
https://github.com/dotnet/csharplang/blob/master/spec/classes.md#properties
Member names reserved for properties
For a property P (Properties) of type T, the following signatures are reserved:
T get_P();
void set_P(T value);
In the case where you have color
property, set_color(...)
is reserved and that's why you can't have set_color
property too, since it tries to compile to the same signature.
In the case where you have Color
property, set_Color(...)
is reserved for it and that's why Set_Color
(note the Capital letter) works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With