我不知道什麼是與此代碼的問題..它說不能將字符串轉換爲對象..類似的東西..C#的Hashtable問題
//lvLogs <-- ListView (2 colums)
Hashtable serverLogs = new Hashtable();
serverLogs.Add("a", "aw");
serverLogs.Add("b", "ew");
serverLogs.Add("c", "iw");
foreach (DictionaryEntry h in serverLogs)
{
lvLogs.Items.Add(h.Key).SubItems.Add(h.Value);
}
但是這個代碼工作正常..
Hashtable serverLogs = new Hashtable();
serverLogs.Add("a", "aw");
serverLogs.Add("b", "ew");
serverLogs.Add("c", "iw");
foreach (DictionaryEntry h in serverLogs)
{
//lvLogs.Items.Add(h.Key).SubItems.Add(h.Value);
//lvi.SubItems.Add(h.Value);
lvLogs.Items.Add(h.Key + " - " + h.Value);
}
我怎樣才能從lvLogs中的列中分離鍵和值?
使用Key.ToString()和Value.ToString()。但字典<字符串,字符串>是更好的,因爲別人建議 – 2011-04-18 10:27:17