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"更好.


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01