有序列表

/*
有序列表
键值对的表示
一个键只能有一个值,如果需要多个值,使用Lookup类
*/
using System.Collections.Generic;

namespace Frank
{
	public class Test
    {
		//程序入口
        public static void Main(string[] args)
        {
			SortedList<string,string> books = new SortedList<string,string>();
			books.Add("1","2sad");
			books.Add("2","sadsad");
			books["3"] = "sadasda";//还可以使用索引器添加元素,如果已经存在键,那么就更新。

			foreach(KeyValuePair<string,string> item in books)
			{
				System.Console.WriteLine(item.Key+"--"+item.Value);
			}
			foreach(string item in books.Keys)//迭代里面所有的Key
			{
				System.Console.WriteLine(item);
			}
        }
	}
}

  

posted on 2013-12-05 11:49  wp456  阅读(144)  评论(0)    收藏  举报

导航