Compiler Error CS0170
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 you try to access it. For more information about initializing structs, see Structure types.
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
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for