什么是使用值的一对(三联等),如C#一个值的最佳方式? [英] What's the best way of using a pair (triple, etc) of values as one value in C#?

查看:116
本文介绍了什么是使用值的一对(三联等),如C#一个值的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也就是说,我想有值的元组

That is, I'd like to have a tuple of values.

在我脑海中的用例:

Dictionary<Pair<string, int>, object>

Dictionary<Triple<string, int, int>, object>



是否有内置的类型,如对或三人间?或者有什么实现它的最好方法是什么?

Are there built-in types like Pair or Triple? Or what's the best way of implementing it?

更新有一些通用的元组在答案中描述的实现,但作为元组在词典中的键,你应该additionaly验证的哈希码的正确计算。在另一问题上一些更多的信息

Update There are some general-purpose tuples implementations described in the answers, but for tuples used as keys in dictionaries you should additionaly verify correct calculation of the hash code. Some more info on that in another question.

更新2 我想这也是值得提醒的是,当你使用一些值作为字典的关键,应该是不可改变的。

Update 2 I guess it is also worth reminding, that when you use some value as a key in dictionary, it should be immutable.

推荐答案

我已经实现在C#中的元组库。访问 http://www.adventuresinsoftware.com/generics/ 并点击元组链接。

I have implemented a tuple library in C#. Visit http://www.adventuresinsoftware.com/generics/ and click on the "tuples" link.

这篇关于什么是使用值的一对(三联等),如C#一个值的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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