添加新的类成员如何做这样的事情(不创建中级班): 覆盖和C#
abstract class A
{
public abstract string Text { get; }
}
class B : A
{
string text = "";
public override string Text
{
get { return text; }
}
new public string Text
{
get { return (this as A).Text; }
set { text = value; }
}
}
编译器说:类型“B”已经包含了“文本”的定义。
澄清:如何做到这一点(但无类“中级”):
abstract class A
{
public abstract string Text { get; }
}
class Intermediate : A
{
protected string text = "";
public override string Text
{
get { return text; }
}
}
class B : Intermediate
{
new public string Text
{
get { return (this as A).Text; }
set { text = value; }
}
}
为什么想要这样做吗? – Davecz
我想在A(和子类)中读取属性并在B(和子类)中读取/写入属性 – Michael