Using system;using system.collections.generic;using system.io;using system.linq;using System.Text;using System.threading.tasks;using System.diagnostics;namespace _editdictionary{class KeyValuePair {public KeyVal Uepair () {} public KeyValuePair (string key,string value) {this.key = key; This.value = value; } private string key; public string Key {get {return Key;} set {key = value;} } private string value; public string Value {get {return this.value;} set {this.value = value;} }} class Mydic {list<keyvaluepair> List = new list<keyvaluepair> (); public void Add (string key, String value) {list. ADD (New KeyValuePair (Key,value)); } public bool Containkey (string key) {bool Result=false; foreach (KeyvaluEpair kvp in list) {if (kvp. Key = = key) {result = true; Value + = kvp. Value; Break }} return result; }} class Program {static void Main (string[] args) {Mydi c dic = new Mydic (); string[] arr = file.readalllines (@ "d:\ English-Chinese dictionary txt format. txt", encoding.default);//The second argument is to prevent garbled characters; The first argument is the TXT document of the dictionary (find a large txt dictionary, Test program to be more effective) foreach (string item in arr) {//split word and explain string[] Strarr = Item. Split (New char[]{'},stringsplitoptions.removeemptyentries); if (strarr.length = = 2) {if (!dic). Containkey (Strarr[0])) {dic. ADD (strarr[0],strarr[1]); }}} Stopwatch sw = new Stopwatch(); Sw. Start (); Dic. Containkey ("China"); Sw. Stop (); Console.WriteLine (SW. Elapsed); Console.WriteLine (); Console.read (); } }}
Take:
How to view the execution efficiency of a homemade dictionary