简体   繁体   English

创建具有两个以上参数的元组

[英]Create Tuple with more than 2 arguments

I want to convert 我想转换

List<Tuple<IntPtr, string, string>>

into 进入

Dictionary<IntPtr, Tuple<string,string>>

using 使用

ToDictionary

ie

var T = new List<Tuple<IntPtr, string, string>>();
T.ToDictionary(/*I cannot figure out the right syntax*/);

All examples I could find have just 2 arguments while I have 3. 我可以找到的所有示例只有2个参数,而我只有3个。

You should use Enumerable.ToDictionary overload which accepts both key and value selectors: 您应该使用Enumerable.ToDictionary重载,该重载同时接受键和值选择器:

T.ToDictionary(t => t.Item1, t => Tuple.Create(t.Item2, t.Item3))

But keep in mind, that there should not be duplicated pointers in your list. 但是请记住,列表中不应有重复的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM