12

How can i cast

from ObservableCollection<TabItem> into ObservableCollection<object>

this doesnt work for me

(ObservableCollection<object>)myTabItemObservableCollection

Using classic SQL:

select [distinct] number
from list_a
where number not in (
    select distinct number from list_b
);

I've put the first "distinct" in square brackets since I'm unsure as to whether you wanted duplicates removed (remove either the brackets or the entire word). The second "distinct" should be left in just in case your DBMS doesn't optimize IN clauses.

It may be faster (measure, don't guess) with an left join along the lines of:

select [distinct] list_a.number from list_a
left join list_b on list_a.number = list_b.number
where list_b.number is null;

Same deal with the "[distinct]".

4

7 に答える 7

13

you should copy like this

return new ObservableCollection<object>(myTabItemObservableCollection);
于 2009-07-29T08:25:55.183 に答える
12

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...
于 2009-07-29T08:26:25.993 に答える
4

あなたが使用できるIEnumerable.Cast<T>()

于 2009-07-29T08:26:59.423 に答える
0

すべての回答に感謝しますが、私はこの問題を「helpermethode」で自分で解決したと思います。

おそらく、これにはもっと良い方法やlinqステートメントがあります。

private void ConvertTabItemObservableCollection()
{
  Manager manager = this.container.Resolve<Manager>();
  foreach (var tabItem in manager.ObjectCollection)
  {
    TabItemObservableCollection.Add((TabItem)tabItem);
  }
}
于 2009-07-29T08:50:32.950 に答える
0

You can't. ObservableCollection<TabItem> does not derive from ObservableCollection<object>.

If you explain why you would want to perhaps we can point out an alternative interface you can use.

于 2009-07-29T08:25:28.490 に答える