==================================主程序
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();
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。