I have a List of strings[].
I want to use Linq to return one field of the string[] from the List<>.
Currently I am doing this:
string[] Cashrow = ParsedSales.First(x=>x.Contains("CALC CASH"));
double Cash= Convert.ToDouble(Cashrow[1]);
which works just fine. My question is if it is possible to write this in a single statement?
I would like a LINQ query that returns the individual field rather than the row.
Thanks.
Sure, instead of getting the first, compose the query with a Where
and a Select
:
double cash = ParsedSales
.Where(x => x.Contains("CALC CASH"));
.Select(x => Convert.ToDouble(x[1]))
.First();
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.