'Property name' 不是標記成 abstract 或 extern,因此必須宣告主體。 自動實作屬性必須同時定義 get 與 set 存取子。

除非規則屬性標記成 abstract extern ,或是 partial 類型的成員,否則必須提供主體。 自動實作屬性未提供存取子主體,但必須同時指定這兩個存取子。 若要建立唯讀自動實作屬性,請將 set 存取子設為 private

更正這個錯誤

  • 提供遺漏的主體或存取子,或是在其上和 (或) 其封入類型上使用 abstract extern partial (類型) 修飾詞。
  • 下列範例會產生 CS0840:

    // cs0840.cs  
    // Compile with /target:library  
    using System;  
    class Test  
        public int myProp { get; } // CS0840  
        // to create a read-only property  
        // try the following line instead  
        public int myProp2 { get; private set; }  
    
  • 自動實作的屬性
  •