c# - How can you create a collection based on multiple IEnumerables -
a class want operate on provides getters of type ienumerable<x>
, ienumerable<y>
x & y subclasses of base type t. want iterate on contents of both treating them type t. there handy way concatenate both can seen ienumerable<t>
?
example:
ienumerable<headerpart> headers = templatefile.maindocumentpart.headerparts; ienumerable<footerpart> footers = templatefile.maindocumentpart.footerparts; list<openxmlpart> result = new list<openxmlpart>(); result.concat<openxmlpart>(footers);
headerpart , footerpart both subclasses of openxmlpart 3rd line fails:
'system.collections.generic.ienumerable' not contain definition 'concat' , best extension method overload 'system.linq.enumerable.concat(system.collections.generic.ienumerable, system.collections.generic.ienumerable)' has invalid arguments
note, can't change either of source data, need create new collection - want foreach
on it.
you can use cast function convert ienumerable<x>
ienumerable<t>
, concat
append second series
something like:
listb.cast<a>().concat(listc.cast<a>())
Comments
Post a Comment