c# 4.0 - How to convert given data into IEnumerable object using LINQ -
i have below code in c# 4, trying use linq ordering, grouping.
ilist<component> components = component.organizationalitem.organizationalitem.components(true); ienumerable<component> baggage = components.where(x => x.isbasedonschema(constants.schemas.baggageallowance.tostring())) .orderby(x => x.componentvalue("name").stringvalue("code")) .groupby(x => x.componentvalue("name").stringvalue("code")); in above sample when trying use groupby giving error, please see below:
error 1 cannot implicitly convert type 'system.collections.generic.ienumerable>' 'system.collections.generic.ienumerable'. explicit conversion exists (are missing cast?)
the result of groupby igrouping<string, component> - it's sequence of groups of components, rather 1 sequence of components. that's whole point of grouping. should fine:
ienumerable<igrouping<string, component>> baggage = ... query before ...; or use implicit typing:
var baggage = ...; you can iterate on groups:
foreach (var group in baggage) { console.writeline("key: {0}", group.key); foreach (var component in group) { ... } }
Comments
Post a Comment