c# - Lambda Statements in Linq -
is possible 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 example. know foreach loop sufficient querying whether possible or not.
i tried it, , it's saying:
cannot convert lambda expression type system.collections.ienumerable<csquery.idomobject> because it's not delegate type
edit: group custom class. groups collection of csquery dom objects. can think of them collection of html anchor elements. ienumerable.
i think you're looking this:
groupscollection = groups.select(g => new group(g.attributes["id"].value, g.attributes["title"].value)).tolist();
explanation:
select()
projects each element of sequence new form. (from msdn)
it's transformation function takes 1 ienumerable , transforms it, in whatever way like, ienumerable, seems want here.
Comments
Post a Comment