木子屋 Dnawo's BLOG

SortedList<TKey, TValue>使用示例

👤 dnawo 📅 2009-04-15 👁 5075 👍 0 💬 0 🔄 本站原创
SortedList<TKey, TValue>表示键/值对的集合,并且各个键/值对自动按照键进行排序,示例如下:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedList<string, int> list = new SortedList<string, int>();
            list.Add("d", 4);
            list.Add("c", 3);
            list.Add("a", 1);
            list.Add("b", 2);

            foreach (KeyValuePair<string, int> item in list)
            {
                Console.WriteLine(item.Key + "," + item.Value.ToString());
            }

            Console.ReadKey();
        }
    }
}

输出如下:

a,1
b,2
c,3
d,4

评论(0)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 PS中将单个切片保存成图片 下一篇 → 抽象类和接口、抽象方法和虚方法的比较