IEnumerable property without type

China☆狼群 提交于 2019-12-06 20:39:08

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/17703353/ienumerable-property-without-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!