请问.NET支持的元组在C#未来的版本?版本、未来、NET

2023-09-02 01:27:13 作者:佐佐木惠理

NET 3.5的不支持的元组。太糟糕了,但不知道.NET的未来版本是否会支持元组或不?

.Net 3.5 doesn't support tuples. Too bad, But not sure whether the future version of .net will support tuples or not?

推荐答案

我刚刚看了这篇文章从MSDN杂志:的楼元组

I've just read this article from the MSDN Magazine: Building Tuple

下面是摘录:

即将到来的4.0版本的Microsoft的   .NET框架引入了一种新类型   所谓System.Tuple。 System.Tuple是   固定大小的集合   多相类型的数据。      

The upcoming 4.0 release of Microsoft .NET Framework introduces a new type called System.Tuple. System.Tuple is a fixed-size collection of heterogeneously typed data.    

一样的阵列,一个元组具有固定   一旦它具有不能改变大小   被创建。与数组,每个   在元组元件可以是不同的   类型,并且一个元组是能够保证   强类型的每个元素。

Like an array, a tuple has a fixed size that can't be changed once it has been created. Unlike an array, each element in a tuple may be a different type, and a tuple is able to guarantee strong typing for each element.

有一个已经一个例子   元组漂浮在微软   .NET框架,在   System.Collections.Generic命名空间:   KeyValuePair。而KeyValuePair可以被认为是相同的   作为元组,因为它们都是   持有两件事情的类型,   KeyValuePair感觉不同   元组,因为它唤起的关系   这两个值它存储(之间   有充分的理由,因为它支持   Dictionary类)。

.NET 5.0 RC 2 发布,正式版将在 11 月 .NET Conf 大会上发布

There is already one example of a tuple floating around the Microsoft .NET Framework, in the System.Collections.Generic namespace: KeyValuePair. While KeyValuePair can be thought of as the same as Tuple, since they are both types that hold two things, KeyValuePair feels different from Tuple because it evokes a relationship between the two values it stores (and with good reason, as it supports the Dictionary class).

此外,元组可以随意   大小,而KeyValuePair只持有   两件事情:一个关键字和一个值

Furthermore, tuples can be arbitrarily sized, whereas KeyValuePair holds only two things: a key and a value.

虽然有些语言,如F#中对元组特殊的语法,你可以使用任何语言的新的共同元组类型。重温第一个例子中,我们可以看到,虽然有用,元组可以是过于冗长的语言没有语法,元组:

While some languages like F# have special syntax for tuples, you can use the new common tuple type from any language. Revisiting the first example, we can see that while useful, tuples can be overly verbose in languages without syntax for a tuple:

class Program {
    static void Main(string[] args) {
    	Tuple<string, int> t = new Tuple<string, int>("Hello", 4);
    	PrintStringAndInt(t.Item1, t.Item2);
    }
    static void PrintStringAndInt(string s, int i) {
    	Console.WriteLine("{0} {1}", s, i);
    }
}

从C#3.0使用var关键字,我们可以删除类型签名的元组变量,它允许稍微更可读code。

Using the var keyword from C# 3.0, we can remove the type signature on the tuple variable, which allows for somewhat more readable code.

var t = new Tuple<string, int>("Hello", 4);

我们还添加了一些工厂方法静态的元组类,它可以更容易地在支持的类型推断,如C#语言建立的元组。

We've also added some factory methods to a static Tuple class which makes it easier to build tuples in a language that supports type inference, like C#.

var t = Tuple.Create("Hello", 4);
 
精彩推荐
图片推荐