使用英语阅读

通过


编译器错误 CS0170

使用了可能未赋值的字段“field”

结构中的字段在使用前未初始化。 若要解决此问题,首先确定哪个字段尚未初始化,然后将其初始化,再尝试访问该字段。 有关初始化结构的详细信息,请参阅结构类型

下面的示例生成 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  
   }  
}