I've developed code that generates a list when the following input data is entered:
-
Size of the list (or how many " Indexes")
-
The values that will populate the " Indexes ".
Values are collected within a method entered in the public class " ListMethod ". I would like to be able to access them later after completion. Follow the code below.
Declaring the method (out of Main()
)
public void GenerateList(int Length)
{
int count = 1;
List<int> Numbers = new List<int> ();
for(int c = 0; c < Length; c++)
{
Console.WriteLine("Qual é o {0}º número da lista?",count);
Numbers.Add(int.Parse(Console.ReadKey())
count++;
}
}
Using the method (within Main()
)
ListMethod insertList = new ListMethod();
Console.WriteLine("Qual é o tamanho da lista?");
int ListLength = int.Parse(Console.ReadLine());
insertList.GenerateList(ListLength);
Console.ReadKey();