I have a custom list of type 'Sales' called SalesList. The class Sales has a fields, of type double and datetimes. The field I am interested in is of type double and call Value_USD. The list contains approx. 10,000 items at runtime.
What I would like to do is select a section of SalesList. Say all the elements from 150 to 350 and select the Value_USD into a new List of type double.
I know I could use GetRange if the lists were of the same type.
尝试这个:
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
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.