是什么要求旨在解决元组? [英] What requirement was the tuple designed to solve?

查看:113
本文介绍了是什么要求旨在解决元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看着元组的新的C#功能。我很好奇,是什么问题就是旨在解决元组?

I'm looking at the new C# feature of tuples. I'm curious, what problem was the tuple designed to solve?

你有什么用元组在您的应用程序?

What have you used tuples for in your apps?

更新

感谢您的答案迄今,让我看看,如果我有事情直接在我的脑海。
一个元组的一个很好的例子已经指出的坐标。这是否正确?

Thanks for the answers thus far, let me see if I have things straight in my mind. A good example of a tuple has been pointed out as coordinates. Does this look right?

var coords = Tuple.Create(geoLat,geoLong);

然后使用元组,像这样:

Then use the tuple like so:

var myLatlng = new google.maps.LatLng("+ coords.Item1 + ", "+ coords.Item2 + ");

这是否正确?

推荐答案

在写程序是非常常见的要逻辑组合在一起的一组值不具有足够的共性来证明决策的一类。

When writing programs it is extremely common to want to logically group together a set of values which do not have sufficient commonality to justify making a class.

很多编程语言让你在逻辑上组合在一起的一组不相关的值,而不只能用一种方法创建一个类型:

Many programming languages allow you to logically group together a set of otherwise unrelated values without creating a type in only one way:

void M(int foo, string bar, double blah)

逻辑上,这是完全一样的方法M.它有一个参数是整型,字符串,双3元组。但是,我希望你不会实际上使:

Logically this is exactly the same as a method M that takes one argument which is a 3-tuple of int, string, double. But I hope you would not actually make:

class MArguments
{
   public int Foo { get; private set; } 
   ... etc

除非MArguments曾在业务逻辑的一些其他的意思。

unless MArguments had some other meaning in the business logic.

组合在一起一串在一些结构比类更轻巧,否则不相关的数据的概念是在很多,很多地方,不只是方法的形参列表是有用的。它是有用的,当一个方法有两个东西返回,或者当您需要加键的字典了两个数据,而不是之一,等等。

The concept of "group together a bunch of otherwise unrelated data in some structure that is more lightweight than a class" is useful in many, many places, not just for formal parameter lists of methods. It's useful when a method has two things to return, or when you want to key a dictionary off of two data rather than one, and so on.

样的语言F#支持的元组类型本身提供的灵活性,他们的用户很大;它们是数据类型的一个非常有用的集合。首创置业团队决定使用F#团队合作,在一个元组类型的标准化框架,使每一种语言可以从中受益。

Languages like F# which support tuple types natively provide a great deal of flexibility to their users; they are an extremely useful set of data types. The BCL team decided to work with the F# team to standardize on one tuple type for the framework so that every language could benefit from them.

然而,在这一点上没有任何的语言的在C#中的元组的支持。元组就像任何其他的框架类的另一种数据类型;没有什么特别之处他们。我们正在考虑增加对未来的C#假想版本的元组更好的支持。如果任何人有什么样的涉及您想看到的元组的功能有什么想法,我很乐意通过他们的设计团队。现实的情况是不是理论沉思更有说服力。

However, there is at this point no language support for tuples in C#. Tuples are just another data type like any other framework class; there's nothing special about them. We are considering adding better support for tuples in hypothetical future versions of C#. If anyone has any thoughts on what sort of features involving tuples you'd like to see, I'd be happy to pass them along to the design team. Realistic scenarios are more convincing than theoretical musings.

这篇关于是什么要求旨在解决元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆