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.
这篇关于什么时候使用元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么时候使用元组?
基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 如果条件可以为空 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
