noob question on c#: how to create a one-dimensional dynamic array? And how to change it later?
thanks.
Instead of using an array, you can use the List<> object in C#.
List<int> integerList = new List<int>();
To iterate on items contained in the list, use the foreach operator :
foreach(int i in integerList)
{
    // do stuff with i
}
You can add items in the list object with Add() and Remove() functions.
for(int i = 0; i < 10; i++)
{
    integerList.Add(i);
}
integerList.Remove(6);
integerList.Remove(7);
You can convert a List<T> to an array using the ToArray() function :
int[] integerArray = integerList.ToArray();
Here is the documentation on List<> object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With