Last post Mar 19, 2018 11:55 AM by PatriceSc
Mar 19, 2018 11:21 AM|Bradly|LINK
var mp = Products.Where(mpn => mpn.ProductName == App).Take(1);
How can i get the product returned , without using a for each loop ?
for example : Product p = ?? ;
Mar 19, 2018 11:55 AM|PatriceSc|LINK
Hi, depending on what the query is expected to return you could use First, FirstOrDefault, Single or SingleOrDefault. For example if you expect your query to return always 1 row :
var mp = Products.Single(mpn => mpn.ProductName == App);
And it will throw if the query doesn't return exactly one row.