共用方式為


編譯器錯誤 CS1715

更新:2007 年 11 月

錯誤訊息

'Type1': 型別必須是 'Type2' 才能符合覆寫成員 'MemberName'

這個錯誤和編譯器錯誤 CS0508 相同,但 CS0508 現在只適用於有傳回型别的方法,而 CS1715 適用於只有「型別」而非「傳回型別」的屬性 (Property) 和索引子 (Indexer)。

範例

下列程式碼會產生 CS1715。

// CS1715.cs
abstract public class Base
{
    abstract public int myProperty
    {
        get;
        set;
    }
}

public class Derived : Base
{
    int myField;
    public override double myProperty  // CS1715
    // try the following line instead
    // public override int myProperty
    {
        get { return myField; }
        set { myField;= value; }
    }

    public static void Main()
    {
        Derived d = new Derived();
        d.myProperty = 5;
    }
}