Better naming in Tuple classes than quot;Item1quot;, quot;Item2quot;(元组类中的命名比“Item1、“Item2更好.)
问题描述
有没有办法使用 Tuple 类,但提供其中项目的名称?
Is there a way to use a Tuple class, but supply the names of the items in it?
例如:
public Tuple<int, int, int int> GetOrderRelatedIds()
返回 OrderGroupId、OrderTypeId、OrderSubTypeId 和 OrderRequirementId 的 ID.
That returns the ids for OrderGroupId, OrderTypeId, OrderSubTypeId and OrderRequirementId.
最好让我的方法的用户知道哪个是哪个.(调用方法时,结果是result.Item1,result.Item2,result.Item3,result.Item4.不清楚哪个是哪个.)
It would be nice to let the users of my method know which is which. (When you call the method, the results are result.Item1, result.Item2, result.Item3, result.Item4. It is not clear which one is which.)
(我知道我可以创建一个类来保存所有这些 Id,但是这些 Id 已经有它们自己的类,并且为这个方法的返回值创建一个类似乎很愚蠢.)
(I know I could just create a class to hold all these Ids, but it these Ids already have their own classes they live in and making a class for this one method's return value seems silly.)
推荐答案
在 C# 7.0 (Visual Studio 2017) 中有一个新的结构可以做到这一点:
In C# 7.0 (Visual Studio 2017) there is a new construction to do that:
(string first, string middle, string last) LookupName(long id)
这篇关于元组类中的命名比“Item1"、“Item2"更好.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:元组类中的命名比“Item1"、“Item2"更好.
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 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
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
