Pregunta

I am new in C# and I am trying to find a way to generate arrays at runtime! What i want to do is really simple. I want to press a button and store my results to an array and at the same time the program to create another array for the next entries that i would like to put. I search a lot using my articles title or sth like generate name of array, but nothing came up to help me. I would appreciate if someone can propose a solution or key words in order to search the internet and find sth like this.

¿Fue útil?

Solución

You probably want a List<Results>, something like:

List<Results> myResults = new List<Results>();

//...

public void BtnClick(...)
{
    Results results = GetResultsForInput();
    myResults.Add(results);
}

//..
//..

public class Results
{
   public int ID { get; set; }
   public string SomethingElse { get; set; } 
}

I'd read up on generic collections, especially List<>

Otros consejos

it is best to do it in lists

public List<MyClass> myList= new List<MyClass>();

and then

MyClass obj = new MyClass();     
//do some stuff    
myList.Add(obj);    

Okay on you button click event just create a new array of list. For example if you want to save strings in array you can do following:

var names = new List<string>();    
names.Add("test");    
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top