简单的c#翻译
本文关键字:翻译 简单 | 更新日期: 2023-09-27 18:18:57
嗨,我正在使用c#制作一个简单的翻译器,我有一个英语单词列表。如何让程序检查用户输入的单词,并与列表中的单词进行检查,而不需要用一堆&&
请帮忙好吗?
使用List对象的Contains方法
Easy:
- 将所有单词添加到列表
- 使用Contains()方法检查列表
示例:(对不起,这是@Stephane Mathis的答案)
public static class SqlServerKeywords {
public static readonly HashSet<string> SqlServerReservedKeywords = new HashSet<string> {
"ADD",
"EXISTS",
"PRECISION",
"ALL",
"EXIT",
"PRIMARY",
"ALTER",
"EXTERNAL",
"PRINT",
"AND",
"FETCH",
"PROC",
"ANY",
"FILE",
"PROCEDURE",
"AS",
"FILLFACTOR",
"PUBLIC",
"ASC",
"FOR"
};
}
public class OtherClass {
private bool Exists (string myWord) {
var exists = SqlServerReservedKeywords.Contains(myWord);
return exists;
}
}