如何使用一个键和多个值创建自己的字典 [英] how can create my own dictionary with one key and multiple value

查看:120
本文介绍了如何使用一个键和多个值创建自己的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi




如何用一个键和多个值创建我自己的字典



示例



hi

how can create my own dictionary with one key and multiple value

Example

Dictionary<int, string,string,bool,int,string......... > dict = new Dictionary<int, string,string,bool,int,string......... >();

推荐答案

只需将对象中的多个值分组并存储标准字典中的{key,object}对。
Simply group your 'multiple values' in a object and store the {key, object} pair in the standard Dictionary.


你可以简单地创建一个类lik e:



You can simply create a class like:

public class MultipleValues
{
    public string value1;
    public bool value2;
    public int value3;
    // add all the values you need here
}





然后你可以在字典中使用它,如:





and then you can use it in the Dictionary like:

var dict = new Dictionary<int, MultipleValues>();


另一个解决方案可能是在你的字典中使用元组



another solution could be using a tuple within your dictionary

var dictionary = new Dictionary<string, Tuple<string, int>>();


这篇关于如何使用一个键和多个值创建自己的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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