列出C#关键字 [英] List C# keywords
本文介绍了列出C#关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到一种列出所有C#关键字的方法.我需要进行比较,例如:
I'm trying to find a way to list all C# keywords. I need to make a comparison, such as:
if (key == "if" || key == "while" || <further_comparisons>)
{
// do something
}
最好通过搜索这些关键字的列表来做到这一点,而我想不用输入它们就可以做到.
It would be way better to do it by searching in a list of those keywords, and I would like to do it without typing them.
我正在查看System.CodeDom命名空间,以查看是否可以找到某些东西.
I'm looking at System.CodeDom namespace to see if I can find something.
如果任何人都可以告诉我在哪里可以找到它,我将非常感激.预先谢谢你!
If any of you could tell me where I could find it, I would really appreciate it. Thank you in advance!
推荐答案
您可以使用
使用Microsoft.CSharp;
CSharpCodeProvider cs = new CSharpCodeProvider();
然后,您可以使用
var test = cs.IsValidIdentifier("if") //return false
这篇关于列出C#关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文