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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -