Is there a make_tuple for C#?

本文关键字:for tuple there make Is | 更新日期: 2023-09-27 17:50:54

是否有c#/.NET等效的make_tuple ?我想做这样的事情

mylist.Add(new Tuple<string,int>("", 1));
当我创建自己的函数 时,c#似乎支持它。
Tuple<T, U> make_tuple<T, U>(T t, U u) { return new Tuple<T, U>(t, u); }
...
var a = make_tuple(1, ""); //compiles!

但是msdn元组显示没有使用它

  Tuple<string, Nullable<int>>[] scores = 
                { new Tuple<string, Nullable<int>>("Jack", 78),
                  new Tuple<string, Nullable<int>>("Abbey", 92), 
                  ...

有还是没有?我可以用4.5

Is there a make_tuple for C#?

您正在寻找Tuple.Create()方法:

var a = Tuple.Create(1, "");