Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

c# - 无法转换列表 <List<double> >列出 <double>(Cannot convert List<List<double>> to List<double>)

I created a list which has 100 list each with 60 values, I need to run all of those 6000 values held within the list called population through a test (shown at the bottom error) and im not sure how i would go about converting the List<List<double>> to List<double> , or if i even can

(我创建了一个包含100个列表的列表,每个列表具有60个值,我需要通过测试运行列表中称为“人口”的所有6000个值(显示在底部错误),并且我不确定如何转换List<List<double>>List<double> ,或者我什至可以)

ttps://i.stack.imgur.com/eByu6.png

  ask by jason7762 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can either start off with a List<double> and use AddRange , so that you flatten the collections.

(您可以从List<double>并使用AddRange ,以便展平集合。)

Or you can convert it using SelectMany , like this:

(或者,您可以使用SelectMany进行转换,如下所示:)

var list = new List<double>();
foreach (...)
{
    list.AddRange(someOtherList);
}

// Or

var list = new List<List<double>>();
var flattenedList = list.SelectMany(x => x);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...