我必须从数组中填充元组数组:
我的数组= [1,0.004,5,0.03]
应将其移至元组数组Tuple<int,double>
(1,0.004), (5,0.03)
我正在使用c#。你能帮我吗?
答案 0 :(得分:3)
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]));}
答案 1 :(得分:0)
使用&#34;%&#34;
循环期间知道你的号码是否成对答案 2 :(得分:0)
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));