字典类:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Dict
{
public class ClassDict
{
private SortedDictionary<string,string> words = new SortedDictionary<string,string>();
public ClassDict()
{
words.Add("lock", "锁");
words.Add("sort", "排序");
words.Add("software", "软件");
words.Add("hardware", "硬件");
words.Add("name", "名字");
words.Add("engine", "发动机");
words.Add("frame", "车架");
words.Add("file", "文件");
words.Add("folder", "文件夹");
words.Add("computer", "电脑");
words.Add("china", "中国");
}
public string Translate(string sEnglish)
{
if (words.ContainsKey(sEnglish))
{
return words[sEnglish];
}
return null;
}
}
}
查字典:
private void button1_Click(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(textBox1.Text.Trim())==false)
{
ClassDict classDict1 = new ClassDict();
char c1 = textBox1.Text.Trim()[0];
if ((int)c1 >= 0x4e00 && (int)c1 <= 0x9fa5)
{
//如果是汉字,就查英文
}
else
{
//如果是英文,就查汉字
textBox2.Text = classDict1.Translate(textBox1.Text.Trim().ToLower());
}
}
}