What and When to use Tuple?(什么时候使用元组?)
问题描述
请有人解释一下元组是什么以及如何在现实世界场景中使用它.我想了解这如何丰富我的编码体验?
May someone please explain what a Tuple is and how to use it in a Real World Scenario. I would like to find out how this can enrich my coding experience?
推荐答案
这个 msdn 文章 用示例很好地解释了这一点,元组是一种具有特定数量和元素序列的数据结构".
元组通常有四种使用方式:
Tuples are commonly used in four ways:
表示单个数据集.例如,一个元组可以表示一个数据库记录,它的组件可以表示记录的各个字段.
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.
提供对数据集的轻松访问和操作.
To provide easy access to, and manipulation of, a data set.
不使用out参数从一个方法返回多个值(在 C# 中)或 ByRef
参数(在 Visual Basic 中).
To return multiple values from a method without using out parameters
(in C#) or ByRef
parameters (in Visual Basic).
通过单个参数将多个值传递给方法.为了例如,Thread.Start(Object)
方法有一个参数允许您为线程执行的方法提供一个值启动时间.如果您提供 Tuple
对象作为方法参数,您可以为线程的启动例程提供三个数据项.
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.
这篇关于什么时候使用元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候使用元组?


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01