I looked previous questions but it didn't help. I have a very simple function written in c#. It give me compiler error "Use of unassigned local variable 'linea' " (line (2)). What could be wrong? And could tell me how to correct it please?
public void llenarTabla()
{
int idx;
string[] linea; (1)
for (idx = 0; idx < numListas; idx++)
{
linea[0] = Convert.ToString(idx); // (2)
switch(OrdenListas[idx]){
case 0: linea[1] = "Crescente"; break;
case 1: linea[1] = "Decrescente"; break;
case 2: linea[1] = "Aleatorio"; break;
default: linea[1] = "No especificado" ; break;
}
linea[2] = Convert.ToString(LongitudListas[idx]);
}
}
I already saw the reference "Compiler error if a variable is used but it might be not initialized. But as far I see the variable string[] (indexes:0,1,2) is inizialized in every case except numlistas = 0 (numlistas is a class parameter and its value is supposed to be >=1).
I also tried to change line (1) and (2) to:
(1) List<string> linea;
(2) linea.Add(Convert.ToString(idx));
but same error (when I tried to change line (1) and (2) I put as a comment all the following lines.
Thank you in advance for every help