Consider this,
class Item
{
public string ID { get; set;}
public string Description { get; set; }
}
class SaleItem
{
public string ID { get; set;}
public string Discount { get; set; }
}
var itemsToRemoved = (List<Item>)ViewState["ItemsToRemove"];
// get only rows of ID
var query = from i in itemsToRemoved select i.ID;
var saleItems= (List<SaleItem>)ViewState["SaleItems"];
foreach (string s in query.ToArray())
{
saleItems.RemoveItem(s);
}
How can I write this LINQ phrase using IEnumerable/List Extension methods
// get only rows of ID
var query = from i in items select i.ID;
thanks in advance.
That one’s easy:
A
selectclause always corresponds to a call toSelect. Some of the other operators end up with a rather more complex expansion 🙂 If you work hard, you can get the compiler to do some very odd stuff…You can find all the details of this and other query expression translations in section 7.16 of the C# specification (v3 or v4).
<plug>You could also buy C# in Depth, 2nd edition and read chapter 11 if you really wanted to 🙂
</plug>