共用方式為


編譯器警告 (層級 4) CS0649

欄位 'field' 永遠都沒有被指派,因此總是維持其預設值 'value'

編譯器偵測到從未指派值的未初始化私人或內部欄位宣告。

備註

只有在明確進行建置重建作業期間,才會報告此警告。 在 IDE 中輸入時,它不會出現在 IntelliSense 診斷中。 這表示如果您使用欄位或移除欄位來修正警告,則警告可能會保留在錯誤清單中,直到您再次建置或重建專案為止。

下列範例會產生 CS0649:

// CS0649.cs  
// compile with: /W:4  
using System.Collections;  
  
class MyClass  
{  
   Hashtable table;  // CS0649  
   // You may have intended to initialize the variable to null  
   // Hashtable table = null;  
  
   // Or you may have meant to create an object here  
   // Hashtable table = new Hashtable();  
  
   public void Func(object o, string p)  
   {  
      // Or here  
      // table = new Hashtable();  
      table[p] = o;  
   }  
  
   public static void Main()  
   {  
   }  
}