是否有可能创造一些IGrouping对象 [英] Is it possible to create some IGrouping object
问题描述
我有名单,其中,IGrouping<字符串,字符串>>
时在某种程度上可能的新项目添加到这个名单?或者实际上,是有可能创造一些IGrouping对象?
Is is somehow possible to add new item to this list? Or actually, is it possible to create some IGrouping object?
推荐答案
如果你真的想创建自己的 IGrouping< TKEY的,TElement>
,这是一个简单的接口实施
If you really wanted to create your own IGrouping<TKey, TElement>
, it is a simple interface to implement:
public class MyGrouping<TKey, TElement> : List<TElement>, IGrouping<TKey, TElement>
{
public TKey Key
{
get;
set;
}
}
本类从继承名单,其中,T&GT;
并实现了 IGrouping
接口。除了对被要求的的IEnumerable
和的IEnumerable&LT; TElement&GT;
(其中名单,其中,T&GT ;。
满足)的唯一属性来实现的键
This class inherits from List<T>
and implements the IGrouping
interface. Aside of the requirement of being an IEnumerable
and IEnumerable<TElement>
(which List<T>
satisfies) the only property to implement is Key
.
从这里,你可以创建所有的 MyGrouping&LT;字符串,字符串&GT;
你要的,并将它们添加到您的名单,其中,IGrouping&LT;字符串,字符串&GT ;&GT;
From here you could create all the MyGrouping<string, string>
s you want and add them to your List<IGrouping<string,string>>
.
这篇关于是否有可能创造一些IGrouping对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!