In the example below, the compiler generates an error "Use of unassigned local variable r
", even though I assign the variable in loop before using it. Why does the compiler generate this error?
static void Main(string[] args)
{
float r;
for (int i = 0; i < 100; i++)
r = i; // assigned here
Console.WriteLine(r); // error: use of unassigned local variable
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…