C#词典一键多个值 [英] c# dictionary one key many values

查看:253
本文介绍了C#词典一键多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个数据存储,让我来存储一些数据。

I want to create a data store to allow me to store some data.

第一个想法是创建一个字典,你有1键和多个值,所以有点像一个一对多的关系。

The first idea was to create a dictionary where you have 1 key with many values, so a bit like a one to many relationship.

我觉得字典只有1项的值。

I think the dictionary only has 1 key value.

怎么回事,我可以存储这些信息?

How else could I store this information?

推荐答案

您可以使用第二泛型类型的列表。比如字符串的字典一个字符串键入:

You can use a list for the second generic type. For example a dictionary of strings keyed by a string:

Dictionary<string,List<string>> myDict;

这篇关于C#词典一键多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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