定義一個接口,創建一個類使用它,有一個常見的錯誤會導致編譯不通過。
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;
}
即可通過翻譯。