linq - Concatenating Two Different IEnumerable Objects in C# -
i have got 2 different ienumerable objects, properties similar in both classes,now want concatenate/merge them, both results can assigned repeater datasource, below sample code.
ienumerable<icacheditem> cacheold = cache<string>.cacheditems; //my old cache class, here fetching cached items ienumerable<caching.icacheditem> cachenew = caching.cache<string>.cacheditems; //my new class cached items var combined = cachenew.cast<icacheditem>().concat(cacheold); //trying concat both repeater.datasource = combined.orderby(entry => entry.region + ":" + entry.prefix + ":" + entry.key); //assigning datasource repeater.databind();
combined object coming blank, suggestions.
update: have got these in class
public class cacheditem<t>: icacheditem { public cacheditem(string key, string prefix, t value) : this(cacheregion.site, prefix, key, value) { } }
do need modify class?
you can use select
convert new items old items. assuming have appropriate constructor, can this:
var combined = cachenew.select(newitem => new oldcacheditem(newitem)).concat(cacheold);
the result of type ienumerable<icacheditem>
. should replace oldcacheditem
name of old cached item type implements icacheditem
.
Comments
Post a Comment