【发布时间】:2014-09-11 09:40:24
【问题描述】:
我有这个 Class Form1.cs 我在其中创建了我的 GUI,它还有一个具有以下功能的组合框:
string SelectedItemName = (string)comboBox2.SelectedItem.ToString();
Console.WriteLine(SelectedItemName);
if (comboBox2.SelectedIndex > -1)
{
testvariabel2.GetSessionName();
}
所以我检查用户是否从 ComboBox 中选择了某些内容,然后在我的其他类 CTestRack.cs 中调用函数 GetSessionName。
Dictionary<string, Dictionary<string, string>> newDictionary = new Dictionary<string,Dictionary<string, string>>();
foreach (SectionData section in data.Sections)
{
var keyDictionary = new Dictionary<string, string>();
foreach (KeyData key in section.Keys)
keyDictionary.Add(key.KeyName.ToString(), key.Value.ToString());
newDictionary.Add(section.SectionName.ToString(), keyDictionary);
if (newDictionary.ContainsKey(testvariabel.SelectedItemName))
{
Console.WriteLine("Key: {0}, Value: {1}", keyDictionary[testvariabel.SelectedItemName]);
}
else Console.WriteLine("Couldn't check Selected Name");
}
在这里,我想检查我的字典中是否存在 String SelectedItemName,但我总是收到 Systen.ArgumentNullException,即我的 CTestRackClass 中的 String SelectedItemName 为 NULL。
现在我的问题是,如何在 CTestRack 中的字典中搜索其他类中设置的字符串 表格1?
【问题讨论】:
-
看看这个post
标签: c# string linq dictionary