c# – List of two or more values

Question:

How to create a list in a class that has multiple values? Roughly speaking, do something like:

List<int,int,double,int> array = new List<int,int,double,int>();
array.Add(4,5,4.3,5);
Console.WriteLine(array[0][2]);

Answer:

Tuple

List<Tuple<int,int,double,int>> array = new List<Tuple<int,int,double,int>>();
array.Add(Tuple.Create(4,5,4.3,5));
Console.WriteLine(array[0].Item3);

ValueTuple:

List<(int,int,double,int)> array = new List<(int,int,double,int)>();
array.Add((4,5,4.3,5));
Console.WriteLine(array[0].Item3);
Scroll to Top