我有用 C# 编写的接口,它是否已经由类实现。我是否可以在接口中添加一个可选属性而不修改现有的已实现类?
例如
public interface IShape
{
int area { get; }
}
public class FindWindow : IShape
{
public int area
{
get
{
return 10;
}
}
}
在这个 FindWindow 中已经写好了。我是否可以添加一个可选属性而不在现有类中实现。
IE,
public interface IShape
{
int area { get; }
//optional
//string WindowName{get;}
}
public class FindWindow : IShape
{
public int area
{
get
{
return 10;
}
}
//WindowName i am not implementing here
}
public class FindWindowName : IShape
{
public int area
{
get { return 20; }
}
public string WindowName
{
get { return "Stack Overflow"; }
}
}