My god yesterday !! The property can be changed to a method !! As mentioned in, a class inherits the attributes of a class and can use the new method to overwrite this attribute, which makes me surprised. Some people in the reply understand this phenomenon in this way, and attributes are also translated into methods in the intermediate language.
I re-wrote a class
Public class ClassA
{
Private string a = "ClassA ";
// Attributes
Public string
{
Get
{
Return;
}
Set
{
A = value;
}
}
// Field
Public string B = "ClassA B ";
// Method
Public string C ()
{
Return "ClassA C ";
}
// Overload method
Public string D ()
{
Return "ClassA D ";
}
Public string D (string arr)
{
Return "Hello" + arr;
}
}
We use ildasm to open the generated file,
Indeed, the property accessors of a are compiled into the Set_A and Get_A methods. It seems that we have found the answer to this question.
However, the following code overwrites this theory.
Public class ClassB: ClassA
{
// A is an attribute. I hide it by using A method.
New public string ()
{
Return "ClassB ";
}
// B is a field. I hide it by using the method.
New public string B ()
{
Return "ClassB B ";
}
// C is a method. I used a field to hide it.
New public string C = "ClassB C ";
// D is an overloaded method. I used a field to hide it.
New public string D = "ClassB D ";
}
Do you think this code can be compiled, or will there be a warning during compilation ?? The answer is that the Code has been compiled and there are no error messages.
Conclusion: attributes and fields and methods (regardless of returned values) can be hidden using any attribute or field or method with the same name. The methods with parameters can be hidden using the same parameter signature method. Only one field or attribute can be hidden for a batch of overloaded methods.
PS: If you replace the members in Class B with private or protected, overwriting will not work. You need to access the parent class members during access.
Finally, it is very complicated to hide the new Keyword. We recommend that you use members of the same type to hide attributes and methods to hide attributes, so as to avoid unnecessary programming troubles.