字段“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()
{
}
}