什么以及何时使用元组? [英] What and When to use Tuple?

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

问题描述

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

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:

  1. 表示一组数据.例如,元组可以代表一个数据库记录,它的组成部分可以代表记录的各个字段.

  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.

提供对数据集的轻松访问和操作.

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

从一个方法返回多个值而不使用输出参数(在 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.

这篇关于什么以及何时使用元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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