What#39;s the purpose of the Tuple(T1)/Singleton in .net?(.net 中的 Tuple(T1)/Singleton 的目的是什么?)
问题描述
.net 4 中的元组类型之一是 单元素元组.我只是想知道这个结构的目的是什么?
One of the Tuple Types in .net 4 is a Single-Element Tuple. I just wonder what the purpose of this struct is?
我看到的唯一用途是在 8+ 元组 因为它可以分配给 TREST,它实际上是有意义的.是这样吗?还是有其他目的?
The only use I saw is when using in the 8+ Tuple as it can be assigned to TRest, where it actually makes sense. Is that it? Or is there any other purpose?
推荐答案
你得问 BCL 设计者才能确定,但我怀疑既然现实世界中有一个 1-tuples,.NET 框架作者希望在他们的实现中提供等效的对称性.
You'd have to ask the BCL designers to be certain, but I suspect that since there is a 1-tuples in the real world, the .NET framework authors wanted to provide equivalent symmetry in their implementation.
Tuples 是您认为的 数学概念的 .NET 实现一个元组.
现在,既然您要求 Tuple<T> 的编程用途,我会也回答有 .NET 语言(如 F#)可以使用 Tuple<> 用于表示函数的返回值等事物.由于 F# 函数肯定会返回一个 1 元组作为结果 - 它为语言的行为和感觉增加了对称性和一致性.
Now since you're asking for programming uses for Tuple<T>, I would also answer that there are .NET languages (like F#) that could use Tuple<> for representation of things like return values from functions. Since an F# function could certainly return a 1-tuple as a result - it adds symmetry and consistency to the behavior and feel of the language.
您的包含 8 个以上元组的示例也可能是合法的,因为 Rest 属性可以是表示溢出"的 1 元组.
Your example with 8+ tuples is also probably legitimate, in that the Rest property could be a 1-tuple to represent the "overflow".
这篇关于.net 中的 Tuple(T1)/Singleton 的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.net 中的 Tuple(T1)/Singleton 的目的是什么?
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
