现在的位置: 首页 > 综合 > 正文

SortList非泛型和泛型遍历输出形式

2012年02月19日 ⁄ 综合 ⁄ 共 429字 ⁄ 字号 评论关闭
 

非泛型遍历输出

SortedList s1 = new SortedList();
           s1["c"] = 41;
           s1["a"] = 42;
           s1["d"] = 11;
           s1["b"] = 13;
           foreach (DictionaryEntry element in s1)
           {
               string s = (string)element.Key;
               int i = (int)element.Value;
               Console.WriteLine("{0},{1}", s, i);
           } 

 

泛型遍历输出

 

SortedList<string,int> s1 = new SortedList<string,int>();
           s1["c"] = 41;
           s1["a"] = 42;
           s1["d"] = 11;
           s1["b"] = 13;
           foreach (KeyValuePair<string,int>  element in s1)
           {
               string s =element.Key;
               int i = element.Value;
               Console.WriteLine("{0},{1}", s, i);
           }

 

 

 

抱歉!评论已关闭.