<分区>
请有人解释一下元组是什么以及如何在真实世界场景中使用它。我想了解这如何丰富我的编码经验?
<分区>
请有人解释一下元组是什么以及如何在真实世界场景中使用它。我想了解这如何丰富我的编码经验?
最佳答案
这msdn article用示例很好地解释了这一点,“元组是一种具有特定数量和元素序列的数据结构”。
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.
To return multiple values from a method without using out parameters (in C#) or
ByRef
parameters (in Visual Basic).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 aTuple<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/