Wednesday, 28 August 2013

Lambda Statements in Linq

Lambda Statements in Linq

Is it possible to do something like the following in Linq?
List<Group> groupsCollection = new List<Group>();
groups.Select( g => {
String id = g.Attributes["id"].Value;
String title = g.Attributes["title"].Value;
groupsCollection.Add( new Group(id, title) );
} );
This is just an example. I know a Foreach loop would be sufficient but I
was querying whether it would be possible or not.
I tried it, and it's saying:
Cannot convert lambda expression to type
System.Collections.IEnumerable<CsQuery.IDomObject> because it's not a
delegate type
Edit: Group is my custom class.

No comments:

Post a Comment