问题描述
int a, b, n;
...
(a, b) = (2, 3);
// 'a' is now 2 and 'b' is now 3
这种事情会在C#中真正的帮助。在这个例子中'a'和'B'arn't一起封装诸如一位置可能是X和Y。是否以某种形式存在此?
This sort of thing would be really helpfull in C#. In this example 'a' and 'b' arn't encapsulated together such as the X and Y of a position might be. Does this exist in some form?
下面是一个不太简单的例子。
Below is a less trivial example.
(a, b) = n == 4 ? (2, 3) : (3, n % 2 == 0 ? 1 : 2);
亚当·马拉什显示的评论认为:
Adam Maras shows in the comments that:
var result = n == 4 ? Tuple.Create(2, 3) : Tuple.Create(3, n % 2 == 0 ? 1 : 2);
作品不过上面的例子中的排序,他指出了它创造的,而不是更改指定值的新truple。
Sort of works for the example above however as he then points out it creates a new truple instead of changing the specified values.
埃里克利珀要求使用的情况下,因此可能:
Eric Lippert asks for use cases, therefore perhaps:
(a, b, c) = (c, a, b); // swap or reorder on one line
(x, y) = move((x, y), dist, heading);
byte (a, b, c, d, e) = (5, 4, 1, 3, 2);
graphics.(PreferredBackBufferWidth, PreferredBackBufferHeight) = 400;
notallama也有使用的情况下,他们在下面他的回答。
notallama also has use cases, they are in his answer below.
推荐答案
我们已经考虑支持语法糖元组,但它并没有酒吧的C#4.0。这是不太可能的吧对C#5.0;在C#5.0的团队是pretty的忙越来越异步/计谋工作的权利。我们会考虑它的语言假设的未来版本。
We have considered supporting a syntactic sugar for tuples but it did not make the bar for C# 4.0. It is unlikely to make the bar for C# 5.0; the C# 5.0 team is pretty busy with getting async/await working right. We will consider it for hypothetical future versions of the language.
如果你有一个非常坚实的使用情况下是令人信服的,这将帮助我们优先考虑的要素。
If you have a really solid usage case that is compelling, that would help us prioritize the feature.
这篇关于C#多任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!