元组(.NET 4)用于.NET Framework 3.5的等效 [英] Equivalent of Tuple (.NET 4) for .NET Framework 3.5
本文介绍了元组(.NET 4)用于.NET Framework 3.5的等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一类存在于.NET Framework 3.5的,这将是等同于.NET 4 元组?
Is there a class existing in .NET Framework 3.5 that would be equivalent to the .NET 4 Tuple?
我想用它,以便从方法返回多个值,而不是创建一个结构
。
I would like to use it in order to return several values from a method, rather than create a struct
.
推荐答案
不,不是的。Net 3.5。但它不应该是很难创建自己的。
No, not in .Net 3.5. But it shouldn't be that hard to create your own.
public class Tuple<T1, T2>
{
public T1 First { get; private set; }
public T2 Second { get; private set; }
internal Tuple(T1 first, T2 second)
{
First = first;
Second = second;
}
}
public static class Tuple
{
public static Tuple<T1, T2> New<T1, T2>(T1 first, T2 second)
{
var tuple = new Tuple<T1, T2>(first, second);
return tuple;
}
}
更新:移动静态的东西,以一个静态类,允许类型推断。有了更新,你可以写的东西,如 VAR元组= Tuple.New(5,你好);
,它会修复类型隐式
UPDATE: Moved the static stuff to a static class to allow for type inference. With the update you can write stuff like var tuple = Tuple.New(5, "hello");
and it will fix the types for you implicitly.
这篇关于元组(.NET 4)用于.NET Framework 3.5的等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文