سؤال

I'm trying to make a property like the official DataGrid.ItemsSource, from MSDN:

public IEnumerable ItemsSource { get; set; }

This provides the support of any type, in any derived class. With this, I can set something like

var list = new List<ObservableCollection<KeyValuePair<decimal, bool>>>();
MyDataGrid.ItemsSource = list;

But when I try to make a property of an IEnumerable without the Type T, exactly as MSDN says, I get an error on VisualStudio:

Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires 1 type arguments

So, what is wrong?

هل كانت مفيدة؟

المحلول

You need to use the non-generic type System.Collections.IEnumerable.
(note the different namespace)

Note that in .Net 4.0+, you can use IEnumerable<object> instead (due to covariance).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top