View Code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _05_翻译软件 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
Dictionary <string , string> dic = new Dictionary < string, string >();
private void btnChange_Click( object sender, EventArgs e) {
if (dic.ContainsKey(txtEnglish.Text)) {
txtChina.Text = dic[txtEnglish.Text];
} else {
MessageBox .Show("请购买新的字典" );
}
}
private void Form1_Load( object sender, EventArgs e) {
string [] filecon = File .ReadAllLines( "英汉词典TXT格式.txt" , Encoding .Default);//格式遵循abandon v.抛弃,放弃
for (int i = 0; i < filecon.Count(); i++) {
string [] arr = filecon[i].Split(new char[] { ' ' }, StringSplitOptions .RemoveEmptyEntries);
if (!dic.ContainsKey(arr[0])) {
dic.Add(arr[0], arr[1]);
}
}
}
}
}
您可能感兴趣的文章: