c# - 什么以及何时使用元组?

标签 c# .net c#-4.0 .net-4.0 tuples

<分区>

请有人解释一下元组是什么以及如何在真实世界场景中使用它。我想了解这如何丰富我的编码经验?

最佳答案

msdn article用示例很好地解释了这一点,“元组是一种具有特定数量和元素序列的数据结构”。

Tuples are commonly used in four ways:

  1. To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record.

  2. To provide easy access to, and manipulation of, a data set.

  3. To return multiple values from a method without using out parameters (in C#) or ByRef parameters (in Visual Basic).

  4. To pass multiple values to a method through a single parameter. For example, the Thread.Start(Object) method has a single parameter that lets you supply one value to the method that the thread executes at startup time. If you supply a Tuple<T1, T2, T3> object as the method argument, you can supply the thread’s startup routine with three items of data.

关于c# - 什么以及何时使用元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13640322/

相关文章:

c# - 使用来自不同方法的变量

c# - 将 C# 7 代码部署到 VSTS

c# - HtmlDocument.Save (HtmlAgilityPack) 输出不完整的文件

c# - Razor View 如果句子不起作用

c# - 使用 Xsd 验证序列化 WCF 代理类中的 Xml 时缺少架构错误

c#-4.0 - 设置 IEnumerable KeyValuePair

wpf - 如何访问 DataGridTemplateColumn 中的控件以获取值?

c# - 如何从 XmlReader 获取范围内的命名空间

c# - n次求根算法

.net - iPhone/Windows Mobile开发平台的长期潜力