C# 类名中允许使用哪些字符?
在 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 an answer that will help me a lot.
解释:我试图完成的是将类名分成可区分的部分,例如:
EXPLANATION: What I try to accomplish is to divide class name into distinguishable parts for example:
class Person@WorkOffice@Helper@Class
class Person@WorkOffice@Helper@Class
{
}
而且我想到了一种使用某种字符或其他东西的方法,以便能够从这个类名中获取部分 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 don't suggest this solution.
规范详情是 此处.本质上,字符类中的任何 unicode 字符(包括 unicode 转义符)Lu, Ll, Lt, Lm, Lo, Nl, Mn, Mc, Nd, PC 和 Cf.第一个字符是一个例外,它必须是一个字母(classes Lu、Ll、Lt, Lm 或 Lo) 或下划线.此外,如果标识符是关键字,则必须在其前面贴上 @.否则@ 是可选的.
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 character 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.