In addition to solution 1 by
ProgramFox[
^], i'd suggest to read this very interesting article:
C# 4 - Tuples[
^]. MSDN migh be helpful too:
Tuple Class[
^]
Note: Tuples are very useful, but you have to work on specific data type, for example custom class. You can "transform" tuple to custom data type (class) via using Linq query. See:
Using your own defined type in a LINQ query expression[
^]
Let's say, you have custom class as follow:
public class Whatever
{
private string sProp = string.Empty;
private int iVal = 0;
public Whatever()
{
}
public Whatever(string _Prop, int _Val)
{
sProp = _Prop;
iVal = _Val;
}
public string Prop
{
get{ return sProp; }
set{ sProp = value; }
}
public int Val
{
get{ return iVal; }
set{ iVal = value; }
}
}
Now, you want to create list of your data... and change first element:
List<Tuple<string, int>> MyTuple = new List<Tuple<string, int>>()
{
new Tuple<string, int>("A", 1),
new Tuple<string, int>("A", 10),
new Tuple<string, int>("A", 100)
};
List<Whatever> ClassCollectionFromTupple = (from mt in MyTuple
select new Whatever
{
Prop = mt.Item1,
Val = mt.Item2
}).ToList();
Whatever wr = ClassCollectionFromTupple[0];
wr.Val = 3;
Try! And Good Luck!