简体   繁体   中英

There is braces in a C# Class name

I have a class from somewhere. The name is strange, it is called "Something[into]ABC.cs". Is it valid for "[into]" in a class name?

It should be noted that the CLI allows names that are illegal in C# (a trick that the C# compiler itself exploits when it "names" anonymous types): however - a type name cannot contain . (that would signify a namaspace), and a little checking shows that [ / ] must be escaped when used in names; so it would be a\\[b\\] (or a\\\\[b\\\\] when written as a C# string). I think we can conclude, therefore, that you do not have a class named Something[into]ABC.cs . I suspect you have a file named that instead, with the class somewhat more sane.

File names do not define the class name, although it is considered polite to keep the two in sync.

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