Suppose I have this data int[] a = [1,2,3,4,5]
I would like to create Tuple<int,int,bool>[] where the first element is itself, the second is it's double value and the last element is whether it is an even number or not.
That is, the resulting data would be :
(1, 2, false)
(2, 4, true)
(3, 6, false)
(4, 8, true)
(5, 10, false)
One solution I have is to create a list, make a for loop over a array and new each Tuple, add to the list, and then finally use .ToArray on the list. But I think there must be an elegant way to do this. I don't mind using LINQ.
int[] a = [1, 2, 3, 4, 5];
List<Tuple<int,int,bool>> list = new List<Tuple<int, int, bool>>();
{
foreach(int i in a)
{
list.Add(new Tuple<int, int, bool>(i, i * 2, i % 2 == 0));
}
}
return list.ToArray();