C# 接口修饰符“public”对该项无效

定义一个接口,创建一个类使用它,有一个常见的错误会导致编译不通过。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    interface IClown
    {
        public string FunnyThingIHave
        {
            get;
        }
        void Honk();
    }
}


问题就出在 FunnyThingIHave 属性前面的“public”,接口的方法和属性都是公共的,就没有必要留下“public”说明词了。

改为:

        string FunnyThingIHave
        {
            get;
        }

即可通过翻译。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章