For a property P (§10.7) of type T, the following signatures are reserved:
T get_P();
void set_P(T value);
Both signatures are reserved, even if the property is read-only or write-only.
In the example
using System;
class A
{
public int P {
get { return 123; }
}
}
class B: A
{
new public int get_P() {
return 456;
}
new public void set_P(int value) {
}
}
class Test
{
static void Main() {
B b = new B();
A a = b;
Console.WriteLine(a.P);
Console.WriteLine(b.P);
Console.WriteLine(b.get_P());
}
}
a class A defines a read-only property P, thus reserving signatures for get_P and set_P methods. A class B derives from A and hides both of these reserved signatures. The example produces the output:
123
123
456
Do'stlaringiz bilan baham: |