I have to populate array of tuples from array:
My array is = [1,0.004,5,0.03]
It should be moved to array of tuples Tuple<int,double>
(1, 0.004), (5, 0.03)
I m workin with c#. Could you please help me?
var tupleList = new List<Tuple<int,double>>();
for(int i = 0; i < array.Length; i += 2)
{tupleList.Add(new Tuple<int,double>((int)array[i], (double)array[i+1]));}
Play with "%" to know if your number is pair or not during a loop for
var arr = new[] { 1, 0.004, 5, 0.03 };
var arr1 = arr.Where((_, i) => i % 2 == 0);
var arr2 = arr.Where((_, i) => i % 2 == 1);
var result = arr1.Zip(arr2, (a, b) => Tuple.Create((int)a, b));