store data with unkown length
-
Hi,
i have to store amount of int values in an Array, the problem is the number of the values is unknown.
can i use System.array
one more the Array should be defined as a global value
Thanks!!!!!!!!!!!!!!!!!!!!!!!!!
-
Hi,
can i use System.array
You can use an array. However, this makes everything unnecessarily complicated. .NET defines a host of container classes that facilitate this. Those classes are defined in the namespace 'System.Collections.Generic'.
In your case, you'll want to use the 'System.Collections.Generic.List' class. This class behaves almost like a vanilla array, with the important addition that you can dynamically add and remove elements. Have a look at the following code (assuming that you have 'using System.Collections.Generic' at the top of the file, which is the default in C#):
List<int> numbers = new List<Int>(); // Dynamically add numbers: for (int i = 0; i < 100; i++) numbers.Add(i); // Access items just as in an array: Console.WriteLine(numbery[30]);
For details, refer to the MSDN.
-
Konrad Rudolph schrieb:
Hi,
List<int> numbers = new List<Int>(); // Dynamically add numbers: for (int i = 0; i < 100; i++) numbers.Add(i); // Access items just as in an array: Console.WriteLine(numbery[30]);
For details, refer to the MSDN.
thanks for your quick answer.