[英]Select section of list of custom type into new list of type double
I have a custom list of type 'Sales' called SalesList. 我有一个称为“销售”的“销售”类型的自定义列表。 The class Sales has a fields, of type double and datetimes.
Sales类具有一个类型为double和datetimes的字段。 The field I am interested in is of type double and call Value_USD.
我感兴趣的字段类型为double,并调用Value_USD。 The list contains approx.
该列表包含约。 10,000 items at runtime.
在运行时有10,000个项目。
What I would like to do is select a section of SalesList. 我想做的是选择SalesList的一部分。 Say all the elements from 150 to 350 and select the Value_USD into a new List of type double.
说出从150到350的所有元素,然后选择Value_USD到类型为double的新列表中。
I know I could use GetRange if the lists were of the same type. 我知道如果列表属于同一类型,则可以使用GetRange。
尝试这个:
List<double> values = SalesList.Skip(149).Take(200).Select(s => s.Value_USD).ToList()
Use a foreach
loop to loop through your sales list and add the double value to other list like below 使用
foreach
循环遍历您的销售清单,并将double值添加到其他清单中,如下所示
List<double> dlst = new List<Double>();
int counter = 0;
foreach(Sales s in SalesList)
{
counter++;
if(counter >= 150 && counter <= 350)
dlst.Add(s.Value_USD);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.