| using System; using System.Collections; namespace testSortedList PrintList(sl); Console.ReadLine(); private static void PrintList(SortedList sl) } //排序
} } |
使用单链接列表实现 IDictionary。建议用于通常包含 10 个或 10 个以下项的集合。
最后我测试了使用泛类型的Dictionary<T,T>, 尽管msdn上说hashtable和Dictionary的实现是一样的,不过同样的数据,返回的结果却是不同的,我没有找到更多的解释,测试代码如下
| using System; using System.Collections; using System.Collections.Specialized; using System.Collections.Generic; namespace NoSortHashtable { /// <summary> /// Summary description for Class1. /// </summary> public class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add(\"hunan\",\"changsha\"); ht.Add(\"beijing\",\"beijing\"); ht.Add(\"anhui\",\"hefei\"); ht.Add(\"sichuan\",\"chengdu\"); foreach(string str in ht.Keys) { Console.WriteLine(str + \" : \" + ht[str]); } Console.WriteLine(\"------------------------------------\"); Dictionary<String,String> dic = new Dictionary<String,String>(); Console.WriteLine(\"------------------------------------\"); ListDictionary lsdic = new ListDictionary(); |

