将字典映射到字典 [英] Map dictionary to dictionary

查看:90
本文介绍了将字典映射到字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个字典映射到另一个字典,例如Dictionary< string,Class>到字典< string,Class.Value> ?
预先谢谢您.

How to map one dictionary to other for example Dictionary<string,Class> to Dictionary<string,Class.Value> ?
Thanks in advance.

推荐答案

正如您所描述的.
具有两个包含< string,Class>的Dictionary.第二个具有< string,Class.Value>

Class.Value有一些Type,例如字符串,int等.
只需将第二个Dictionary定义为< string,int>.
Just as you describe.
Have two Dictionary one that holds <string, Class> and the second that has <string, Class.Value>

Class.Value has some Type, like a string, int etc.
The second Dictionary just has to be defined as <string, int>.


您可以简单地使用Dictionary<string, Class>并使用键访问Class的值.
例如:

You could simply have a Dictionary<string, Class> and access the Class'' values by using the key.
For example:

Dictionary<string, MyClass> dictionary = new Dictionary<string, MyClass>();
MyClass instance = new MyClass();
dictionary.Add("MyString", instance);
dictionary["MyString"].Value = "SomeValue"



因此,当您指定Dictionary的密钥时,可以直接从Dictionary中访问ClassPropertiesMethods.



So it is possible to directly access the Properties and Methods of your Class from the Dictionary when you specify its key.


这篇关于将字典映射到字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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