技术开发 频道

C#的6种常用集合类大比拼

  (5)SortedList类

  与哈希表类似,区别在于SortedList中的Key数组排好序的。

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
    
class Program
    {
        
public static void Main()
        {
            SortedList sl
= new SortedList();
            sl[
"c"] = 41;
            sl[
"a"] = 42;
            sl[
"d"] = 11;
            sl[
"b"] = 13;
            
foreach (DictionaryEntry element in sl)
            {
                
string s = (string)element.Key;
                
int i = (int)element.Value;
                Console.WriteLine(
"{0},{1}",s,i);
            }
        }
    }
}
0
相关文章