Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top