Trying to get my head into Linq to Objects and for the life of me it escapes me…I want to get a list of all the products where the _name starts with J.
Product prod; for (int i = 0; i < 10;i++ ) { prod = new Product(); prod._Name = 'J' + i.ToString(); prod._Surname = 'F' + i.ToString(); }
Update
Product prod; List<Product> productList = new List<Product>(); for (int i = 0; i < 10;i++ ) { prod = new Product(); prod._Name = 'J' + i.ToString(); prod._Surname = 'F' + i.ToString(); productList.Add(prod); } var query = productList.Where(p=> p._Name.StartsWith('J'));
Thanks Jon
Well you haven’t given a collection of any kind in your code sample, but assuming you have a collection called
productsyou want something like:That will give an
IEnumerable<Product>. If you want aList<Product>just add a call toToList()to the end: