小编Bri*_*Raj的帖子

C#接口创建Optional属性

我有用C#编写的接口,它已经由类实现了.是否有可能在界面中添加一个属性作为可选属性而不修改现有的实现类?

例如

public interface IShape
{
    int area { get; }
}

public class FindWindow : IShape
{
    public int area
    {
        get
        {
            return 10;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在这个FindWindow已经写好了.是否可以添加一个可选属性而不在现有类中实现.

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 …
Run Code Online (Sandbox Code Playgroud)

c# interface

8
推荐指数
3
解决办法
1万
查看次数

标签 统计

c# ×1

interface ×1