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.
这篇关于什么时候使用元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候使用元组?
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
