///?<summary>
///?基本单词项
///?</summary>
public?class?DictItem
{
///?<summary>
///?英文单词
///?</summary>
public?string?DictEnglish{set;?get;}
///?<summary>
///?中文含义
///?</summary>
public?string?DictChinese?{?set;?get;?}
}
///?<summary>
///?字典类
///?</summary>
public?class?Dict
{
///?<summary>
///?字典库
///?</summary>
private?List<DictItem>?DictDB?=?new?List<DictItem>();
public?Dict()
{?
//加载字典数据库
//示例代码
DictDB.Add(new?DictItem?{?DictChinese?=?"中国",?DictEnglish?=?"China"?});
DictDB.Add(new?DictItem?{?DictChinese?=?"美国",?DictEnglish?=?"America"?});
DictDB.Add(new?DictItem?{?DictChinese?=?"梦",?DictEnglish?=?"Dream"?});
}
///?<summary>
///?代码示例
///?</summary>
public?static?void?Demo()
{
Dict?dictDemo?=?new?Dict();
//汉译英示例,下面将返回China
string?english?=?dictDemo.TranslateFromChinese("中国");
//英译汉示例,下面将返回“美国”
string?chinese?=?dictDemo.TranslateFromEnlish?("America");
}
///?<summary>
///?英译汉
///?</summary>
///?<param?name="English"></param>
///?<returns></returns>
public?string?TranslateFromEnlish(string?English)
{
string?Chinese?=?"";
//简单的查找单词库中的相同的英文后,返回对应中文。可以用更多方法实现
for?(int?i?=?0;?i?<?DictDB.Count;?i++)
{
if?(DictDB[i].DictEnglish?==?English)
{
Chinese?=?DictDB[i].DictChinese;?
break;
}
}
return?Chinese;
}
///?<summary>
///?汉译英
///?</summary>
///?<param?name="Chinese"></param>
///?<returns></returns>
public?string?TranslateFromChinese(string?Chinese)
{
string?English?=?"";
//简单的查找单词库中的相同的中文后,返回对应英文。可以用更多方法实现
for?(int?i?=?0;?i?<?DictDB.Count;?i++)
{
if?(DictDB[i].DictChinese?==?Chinese)
{
English?=?DictDB[i].DictEnglish;
break;
}
}
return?English;
}
}