有序列表---SortedList<TKey,TValue>
==================================主程序
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceConsoleApplication6{classProgram{staticvoidMain(string[]args){//有序列表会按照键排序SortedList<string,string>s=newSortedList<string,string>();s.Add("a","1");s.Add("b","3");s["d"]="2";s["c"]="4";Console.WriteLine("--------------【遍历有序列表】-----------------");foreach(varitemins){Console.WriteLine(item.Key+","+item.Value);}Console.WriteLine("--------------【遍历有序列表的值】-----------------");foreach(varitemins.Values){Console.WriteLine(item);}Console.WriteLine("--------------【遍历有序列表的键】-----------------");foreach(varitemins.Keys){Console.WriteLine(item);}//获取有序列表的值【安全获取】stringoutstr;//返回值stringkey="a";//键if(!s.TryGetValue(key,outoutstr)){Console.WriteLine(key+"键不存在");}Console.WriteLine(outstr);Console.ReadKey();}}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。