type case Icollection object into collection object in c#
How can i cast an ICollection object of string type into a Collection object of string type again in c#
So one of my methods return
public s开发者_JS百科tatic ICollection<type1> Filter()
and i need to get this into
Collection<type1> list=Filter();
thanks
var list = new Collection<type1>(Filter());
I think Erno is on the right track becuase you really can't count on your ICollection< T > actually being a Collection< T >. Many many classes including custom classes could implement that interface and that's a very good thing.
Erno's solution 'does the cast' by creating a new Collection by consuming the contents of your ICollection. If that works for you then great.
But I'm not really sure why do you need to 'cast back' in the first place.
精彩评论