标签:sortlist<t> list sort 列表 有序 有序列表
==================================主程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
//有序列表会按照键排序
SortedList<string, string> s = new SortedList<string, string>();
s.Add("a", "1");
s.Add("b", "3");
s["d"] = "2";
s["c"] = "4";
Console.WriteLine("--------------【遍历有序列表】-----------------");
foreach (var item in s)
{
Console.WriteLine(item.Key + "," + item.Value);
}
Console.WriteLine("--------------【遍历有序列表的值】-----------------");
foreach (var item in s.Values)
{
Console.WriteLine(item);
}
Console.WriteLine("--------------【遍历有序列表的键】-----------------");
foreach (var item in s.Keys)
{
Console.WriteLine(item);
}
//获取有序列表的值【安全获取】
string outstr;//返回值
string key = "a";//键
if (!s.TryGetValue(key,out outstr))
{
Console.WriteLine(key + "键不存在");
}
Console.WriteLine(outstr);
Console.ReadKey();
}
}
}本文出自 “程序猿的家” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1547108
标签:sortlist<t> list sort 列表 有序 有序列表
原文地址:http://962410314.blog.51cto.com/7563109/1547108