I have the following problem: I have a function to create an array and as a parameter I pass a constant of the size that it is going to have. I must enter the values to the array by keyboard but when returning the same, it tells me the error of the title.
here the code
namespace Media_CS
{
class Program
{
static void Main(string[] args)
{
const ushort tamanio = 5;
var arreglo = CrearArreglo(tamanio);
}
static ushort CrearArreglo(ushort tamanio)
{
//Declaro el array como ushort y le resto uno a la constante
var arreglo = new ushort[tamanio - 1];
Console.WriteLine("Ingresar valores a almacenar: ");
for (int i = 0, loopTo = arreglo.Length - 1; i <=loopTo; i++)
{
arreglo[i] = Convert.ToUInt16(Console.ReadLine());
}
return arreglo; //linea de error
}
}
}
The error tells you that you cannot convert an array to a variable that is not an array.
to solve the problem your method has to return an array.