C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼
來(lái)源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 22:41:39
C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼
C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼: 代碼如下: Dictionary<string,string> list=new Dictionary<string,string>;//3.0以上版本foreach(var item in list){ Console.WriteLine(item.Key+item.Value);}//KeyValuePair<T,
導(dǎo)讀C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼: 代碼如下: Dictionary<string,string> list=new Dictionary<string,string>;//3.0以上版本foreach(var item in list){ Console.WriteLine(item.Key+item.Value);}//KeyValuePair<T,
代碼如下:
Dictionary<string,string> list=new Dictionary<string,string>;
//3.0以上版本
foreach(var item in list)
{
Console.WriteLine(item.Key+item.Value);
}
//KeyValuePair<T,K>
foreach(KeyValuePair<string,string> kv in list)
{
Console.WriteLine(kv.Key+kv.Value);
}
//通過(guò)鍵的集合取
foreach(string key in list.Keys)
{
Console.WriteLine(key+list[key]);
}
//for循環(huán)遍歷
List<string> test=new List<string>(list.Keys);
for(int i=0;i<list.Count;i++)
{
Console.WriteLine(test[i]+list[test[i]]);
}
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼
C#中Dictionary幾種遍歷的實(shí)現(xiàn)代碼: 代碼如下: Dictionary<string,string> list=new Dictionary<string,string>;//3.0以上版本foreach(var item in list){ Console.WriteLine(item.Key+item.Value);}//KeyValuePair<T,