Create List of Tuples from List using LINQ

本秂侑毒 提交于 2019-12-04 14:32:00

It can be achieved (example for Tuple<Single, Single>) and the following solution isn't very complex, but using loop is clearer and - in case of this particular solution - more efficient (the input list is enumerated twice). Code in C#, don't know VB

var even = inputList.Where((elem, ind) => ind % 2 == 0);
var odd = inputList.Where((elem, ind) => ind % 2 == 1);
var outputList = even.Zip(odd, (a, b) => new Tuple<Single, Single>(a, b)).ToList();

Maybe this will help someone.

var pairs = from p in TheListOfAllLists select (
new Tuple<string, string>( p.ParameterName,p.Value.ToString()));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!