嵌套泛型
我以前问过这个问题,但我没有回答正确的问题,所以错过了答案。
如果我有一个返回 ObservableCollection
的方法,那么我将如何在另一个通用方法中使用它。
将
method2<ObservableCollection<T>>(){}
是要走的路。
我正在尝试创建一个通用的 resultEventArgs,它将 Ado.NET Dataservices 查询的结果传递给所有订阅者。 在里面,我希望能够传递返回的强类型 EntityCollection [Ado.NET 1.5 生成]
所以是的,我的问题措辞为 ObservableCollection
因为我不想得到整个 ado。网络数据服务混乱。
干杯 戴夫
I have asked this before but I didn't get the question right so the answer was missed.
If I have a method that returns an ObservableColletion<T>
how would I then use this in another generic method.
Would
method2<ObservableCollection<T>>(){}
be the way to go.
I am trying to make a generic resultEventArgs that will pass the results of an Ado.NET Dataservices query to all subscribers. Inside that I want ot be able to pass the strongly typed EntityCollection that is returned [Ado.NET 1.5 generated]
So yes, my question is worded ObservableCollection
because i didn't want to get the whole ado.net dataservices confusion.
Cheers
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于; 您要指定 item 类型还是 collection 类型? 如果您只想指定项目,则
T
仅与该项目相关:然后您可以使用
ObservableCollection; order = SomeMethod()
等。如果需要指定集合类型,则可能需要更多泛型类型...但是,调用它比较棘手。 除非列表是参数,否则它无法进行类型推断,这意味着在调用它时必须同时指定
TList
和T
...不太漂亮。It depends; do you want to specify the item type, or the collection type? If you just want to specify the item, then the
T
relates just to the item:Then you can use
ObservableCollection<Order> orders = SomeMethod<Order>()
etc. If you need to specify the collection type, you may need more generic types...However, calling it is trickier. It can't do type inference unless the list is an argument, meaning you have to specify both
TList
andT
when calling it... not pretty.