Compiler Error CS0170
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Compiler Error CS0170 

Error Message

Use of possibly unassigned field 'field'

A field in a structure was used without first being initialized. To solve this problem, first determine which field was uninitialized and then initialize it before attempting to access it. For more information on initializing structs, see Structs (C# Programming Guide) and Using Structs (C# Programming Guide).

The following sample generates 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
© 2016 Microsoft