62,266
社区成员
发帖
与我相关
我的任务
分享namespace 英汉词典
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
Dictionary<string, string> dic = new Dictionary<string, string>();
private void Form1_Load(object sender, EventArgs e)
{// 读取文件内容
string[] txts = File.ReadAllLines("2.txt", Encoding.Default);
//声明一个泛型函数
for (int i = 0; i < txts.Length; i++)
{
string[] txt = txts[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//保存key和value
if (dic.ContainsKey(txt[0]))
{
dic[txt[0]] += " \n" + txt[1];
}
else
{
dic.Add(txt[0], txt[1]);
}
}
}
private void btnEtoC_Click(object sender, EventArgs e)
{
//}
//txtOut.Text = txts[0][0];
//获得用户输入的英文
string txtInStr = txtIn.Text;
if (dic.ContainsKey(txtInStr))
{
//Console.WriteLine(dic[txtInStr]);
txtOut.Text = dic[txtInStr];
}
else
{
MessageBox.Show("请输入正确的单词");
}
}
private void btnCtoE_Click(object sender, EventArgs e)
{
}
}
}
Dictionary<object, object> oo = new Dictionary<object, object>();