Use of the local variable not assigned

0

I execute the following method:

static bool elimino(int[] lista, string[] nombre, string nom, ref int tope) 
    {

        Console.Write("Nombre");
        nom = Console.ReadLine()
        bool e = false;
        for (int i = 0; i < tope; i++)
        {
            if (nom == nombre[i])
            {
                for (int j = i; j < tope - 1; j++)
                {
                    lista[j] = lista[tope - 1];
                    nombre[j] = nombre[j - 1];
                    tope--;
                    e = true;
                    i = tope;
                }
            }
        }
        return e;
    } 

I invoke it in this way (I think it's the right one)

static void Main(string[] args) { 
  string[] nombre; string nom; int opcion, 
  tope = 0, cantidad; bool seguir = true;
  elimino(vector, nombre, nom, ref  tope); 
} 

But anyway he tells me

  

"use of the unmapped local variable nom,

I declare it as string , and even then I mark the error in nom, I can not execute the method to test if it works

    
asked by eleaefe 29.06.2017 в 19:05
source

1 answer

5

The error it gives is the CS0165 where it clearly says:

  

The compiler does not accept the use of uninitialized variables.

Here's the problem:

static void Main(string[] args) { 
  string nom; 
}

You have to initialize the variables (in this case nom ) but with value null to be able to use them.

static void Main(string[] args) { 
  string nom = null;
}
    
answered by 29.06.2017 / 19:21
source