简体   繁体   中英

How to programmatically get the list of symbols restricted in variable names

Just curios is there any way to get the list of symbols that are illegal for naming variables in C# eg brackets of all kinds, commas etc in code? Something like SomeClass.GetIllegalVariableSymbols()

No; there are a lot , for one, when you consider Unicode, and there are also other rules (eg an identifier can contain a number but not begin with one, keywords can't be used as identifiers unless prefixed by an @ , etc.).

You'll need to build your own appropriate for the situation. (What is that, out of curiosity?)

Yes, you can. Just use Path.GetInvalidFileNameChars() method. Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM