我感兴趣的是:c++中类似std::pair的c#是什么?我找到System.Web.UI.Pair类,但我更喜欢基于模板的东西。
谢谢你!
我感兴趣的是:c++中类似std::pair的c#是什么?我找到System.Web.UI.Pair类,但我更喜欢基于模板的东西。
谢谢你!
当前回答
从。net 4.0开始,你有了System。元组<T1, T2>类:
// pair is implicitly typed local variable (method scope)
var pair = System.Tuple.Create("Current century", 21);
其他回答
根据您想要实现的目标,您可能想尝试KeyValuePair。
不能更改条目的键当然可以通过简单地用KeyValuePair的一个新实例替换整个条目来纠正。
不幸的是,没有。你可以使用System.Collections.Generic。KeyValuePair<K, V>在许多情况下。
或者,你可以使用匿名类型来处理元组,至少在本地:
var x = new { First = "x", Second = 42 };
最后一种选择是创建自己的类。
从。net 4.0开始,你有了System。元组<T1, T2>类:
// pair is implicitly typed local variable (method scope)
var pair = System.Tuple.Create("Current century", 21);
如果是关于字典之类的,你要找System.Collections.Generic。KeyValuePair < TKey, TValue >。
c#在4.0版就有了元组。