编译器错误 CS0170
更新:2007 年 11 月
错误消息
使用了可能未赋值的字段“field”
结构中的字段在使用前未初始化。若要解决此问题,首先确定哪个字段尚未初始化,然后将其初始化,再尝试访问该字段。有关初始化结构的更多信息,请参见结构(C# 编程指南)和使用结构(C# 编程指南)。
下面的示例生成 CS0170:
// CS0170.cs
public struct error
{
public int i;
}
public class MyClass
{
public static void Main()
{
error e;
// uncomment the next line to resolve this error
// e.i = 0;
System.Console.WriteLine( e.i ); // CS0170 because
//e.i was never assigned
}
}