没有类型的IEnumerable属性 [英] IEnumerable property without type

查看:62
本文介绍了没有类型的IEnumerable属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从MSDN制作一个像正式的DataGrid.ItemsSource这样的属性:

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;

但是,当我尝试使IEnumerable的属性不带Type T时,正像MSDN所说的那样,我在VisualStudio上收到错误消息:

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

那么,怎么了?

推荐答案

您需要使用非通用类型System.Collections.IEnumerable.
(请注意其他名称空间)

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

请注意,在.Net 4.0+中,您可以改用IEnumerable<object>(由于协方差).

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

这篇关于没有类型的IEnumerable属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆