Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i cast into a ObservableCollection<object>

How can i cast

from ObservableCollection<TabItem> into ObservableCollection<object>

this doesnt work for me

(ObservableCollection<object>)myTabItemObservableCollection
like image 367
Mario Binder Avatar asked Jul 29 '09 08:07

Mario Binder


2 Answers

you should copy like this

return new ObservableCollection<object>(myTabItemObservableCollection);
like image 191
Arsen Mkrtchyan Avatar answered Oct 17 '22 01:10

Arsen Mkrtchyan


Basically, you can't. Not now, and not in .NET 4.0.

What is the context here? What do you need? LINQ has Cast<T> which can get you the data as a sequence, or there are some tricks with generic methods (i.e. Foo<T>(ObservalbleCollection<T> col) etc).

Or you can just use the non-generic IList?

IList untyped = myTypedCollection;
untyped.Add(someRandomObject); // hope it works...
like image 12
Marc Gravell Avatar answered Oct 17 '22 02:10

Marc Gravell