The ArrayList is an old feature, and is deprecated [
^] now because it is a very expensive (memory, time to access) way to create a collection of objects of mixed Types, and using it, errors will not occur at compile-time.
Its use is also ... in almost all cases ... a violation of good OOP/SOLID principles: in good practice all these bits of data you are putting into the ArrayList
mean something. Use a Class (or Struct) to store your data:
public class Data
{
public int Number10 { set; get; }
}
Or, if you must have a structure where you can add multiple Types at run-time, later versions of C# provide the 'ExpandoObject [
^] in the System.Dynamic NameSpace (and, the more complex 'DynamicObject):
dynamic person = new ExpandoObject();
person.Name = "John";
person.Surname = "Doe";
person.Age = 42;
int age = person.Age;
foreach (var kvp in person)
{
Console.WriteLine($"{kvp.ToString()}");
}
[Name, John]
[Surname, Doe]
[Age, 42]