3

I have the following variable:

List<Tuple<DataType, String, List<String>>> items;

I need to create a Dictionary<DataType, String[]> where the DataType is the Tuple's Item1 and the String[] are all the Tuple's Items 2 for that DataType.

So I tried:

Dictionary<DataType, String[]> d = items.GroupBy(x => x.Item1)
    .ToDictionary(x => x.Key, x => x.Value);

This does not compile.

How can I solve this?

4

1 回答 1

9
Dictionary<DataType, String[]> d = items
    .GroupBy(x => x.Item1)
    .ToDictionary(
        g => g.Key,
        g => g.Select(t => t.Item2).ToArray()); //the change is on this line

IGrouping<TKey, TElement>类型没有Value成员。它有一个Key属性和实现IEnumerable<TElement>

于 2013-11-05T21:34:31.393 回答