问题描述
允许使用什么字符,以及C#类名中不允许使用什么。你能帮忙吗?
What characters are allowed and what is not allowed in a C# class name. Could you please help?
编辑:指定。允许使用什么特殊字符。请具体说明,因为链接到50页的高技术语言规格不是一个答案,这将帮助我很多。
To specify. What special characters are allowed. Please be specific, because links to 50 pages specs in high-technical language is not a answer that will help me a lot.
说明:我试图做的是将类名划分为可区分的部分,例如:
EXPLANATION: What I try to acomplish is to divide class name into distinguishable parts for example:
{
}
使用某种角色或其他东西,以便能够从这个类名得到零件Person,WorkOffice,Helper和Class。
And I think about a way of using some kind of character or something else to be able to get parts Person, WorkOffice, Helper and Class from this class name.
是的,我知道这很疯狂,但我需要这样。我知道我可以使用属性和反射来存储这个数据在类元,但不是这样,所以请不要建议这个解决方案。
And yes, I know it's crazy, but I need it that way. I know that I can use attributes and reflection to store this data in class meta but this is not the case, so please not suggest this solution.
推荐答案
规格详情请。基本上,中的任何unicode字符(包括unicode转义) ,,,,, ,,,,,和。第一个字母是一个例外,它必须是字母(类,,,或)或下划线。此外,如果标识符是关键字,您必须在其前面粘贴一个@。 @是可选的。
The spec details are here. Essentially, any unicode character (including unicode escapes) in the character classes Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, Pc, and Cf. The first letter is an exception and it must be a letter (classes Lu, Ll, Lt, Lm, or Lo) or an underscore. Also, if the identifier is a keyword, you must stick an @ in front of it. The @ is optional otherwise.
这篇关于C#类名中允许有什么字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!