usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespaceImport English-Chinese text, cut with string, generic collection stored in English-Chinese dictionary { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Dictionary<string,string> dic =Newdictionary<string,string>(); Private voidForm1_Load (Objectsender, EventArgs e) { //when the form loads//Create a dictionary//Read File string[] lines= File.ReadAllLines ("1.txt", Encoding.default); //traverse each row for(inti =0; I < lines. Length; i++) { string[]words= Lines[i]. Split (New Char[]{' '}, Stringsplitoptions.removeemptyentries); //Merge the Chinese meaning stringChinese =""; for(intj =1; J < words. Length; J + +) {Chinese+ = Words[j];//Merging Chinese meanings } if(!dic. ContainsKey (words[0]))//Judging if there is a word in the dictionary,{dic. ADD (words[0],chinese);//If you don't have the word, add the word and meaning to the dictionary. } Else { //the word already exists in the dictionary,dic[words[0]] +=Chinese; } } } Private voidBtnok_click (Objectsender, EventArgs e) { //remove an English word from the first text box//determine if the word exists in the dictionary, and if it exists, show the Chinese meaning if(DIC. ContainsKey (TxtEnglish.Text.ToLower ())) {Txtchinese.text=Dic[txtenglish.text.tolower ()]; } Else{Txtchinese.text="the word is not included in the dictionary"; } //If it does not exist, the word is not included in the dictionary } }}
Import English-Chinese text, cut with string, generic collection storage of English-Chinese dictionaries