Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用KeyedList获取项目_C#_C# 4.0_Windows Phone 8_Winrt Xaml - Fatal编程技术网

C# 使用KeyedList获取项目

C# 使用KeyedList获取项目,c#,c#-4.0,windows-phone-8,winrt-xaml,C#,C# 4.0,Windows Phone 8,Winrt Xaml,我有一个用C#编写的小类,用来保存数据结构的列表,并使用一个特殊的键来分组项目 public class KeyedList<TKey, TItem> : List<TItem> { public TKey Key { protected set; get; } public IEnumerable<TItem> Items { protected set; get; } public KeyedList(TKey key, IEnu

我有一个用C#编写的小类,用来保存数据结构的列表,并使用一个特殊的键来分组项目

public class KeyedList<TKey, TItem> : List<TItem>
{
    public TKey Key { protected set; get; }
    public IEnumerable<TItem> Items { protected set; get; }

    public KeyedList(TKey key, IEnumerable<TItem> items)
        : base(items)
    {
        Key = key;
        Items = items;
    }

    public KeyedList(IGrouping<TKey, TItem> grouping)
        :base (grouping)
    {
        Key = grouping.Key;
        ???
    }
}
公共类KeyedList:List
{
公钥{protected set;get;}
公共IEnumerable项{protected set;get;}
公钥列表(TKey、IEnumerable项)
:基本(项目)
{
钥匙=钥匙;
项目=项目;
}
公钥列表(I分组)
:基本(分组)
{
Key=grouping.Key;
???
}
}
现在我想访问元素


那么,我要写些什么呢???要获取项的信息?

首先,您不应该存储项,因为它们已经由基类处理:
List

但是如果您真的想这样做,您可以直接将
分组
分配到
,因为
i分组
实现了
IEnumerable


类似于
Items=grouping.Select(g=>g)
public KeyedList(IGrouping<TKey, TItem> grouping)
    :base (grouping)
{
    Key = grouping.Key;
    Items = grouping;
}
public KeyedList(IGrouping<TKey, TItem> grouping)
    :base (grouping)
{
    Key = grouping.Key;
    Items = this;
}