【发布时间】:2013-04-30 09:27:35
【问题描述】:
我想通过使用字符串来查找字典,以便将其复制到新字典中——看起来应该很简单,但我不确定语法。
基本上就是这样:
// the object's myName corresponds to an existing dictionary
string stringdic = myName;
// here's where I try to create a new dictionary containing the values of the existing dictionary
Dictionary<string, int> mySkills = new Dictionary<string, int>(myName);
这里的目标只是创建一个以给定字符串作为其“名称”的对象,并从名称中知道它应该使用一组字典中的哪一个——例如,如果 myName = Bob,我想访问此脚本中的字典 Bob。
因此,引用预先存在的字典以获取其键/值的其他方式也可以工作。速度不是一个大问题,但我想保持代码简单。谢谢!
【问题讨论】:
标签: c# dictionary