C# 无法将字典项添加到列表框
我有一本字典,里面有几项:C# 无法将字典项添加到列表框,c#,windows,.net,C#,Windows,.net,我有一本字典,里面有几项: public static Dictionary<string, string> vmDictionary = new Dictionary<string, string>(); entry.Value[0]和[1]应该是string(如果我没有弄错的话),但出于某种原因,它抱怨它们是chars:Sentry.Value返回KeyValuePair的值组件,在本例中它是一个字符串,当您对该字符串使用索引时,您将得到一个char。我认为你的意思
public static Dictionary<string, string> vmDictionary = new Dictionary<string, string>();
entry.Value[0]和[1]应该是string(如果我没有弄错的话),但出于某种原因,它抱怨它们是chars:S
entry.Value
返回KeyValuePair
的值组件,在本例中它是一个字符串,当您对该字符串使用索引时,您将得到一个char。我认为你的意思是:
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);
您正在尝试在KeyValuePair中添加值的第一个字符。也许你想这么做
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);
item.SubItems.Add(entry.Value[0]);
item.SubItems.Add(entry.Value[1]);
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);