Using underscores in class names

Can _ be used in class names?

What is the best replacement for . when naming? (I am currently using _ .)

+4
source share
6 answers

It is safe to underline one at a time, although you should not use two consecutive underscores. From the C # language specification, section 2.4.2:

Identifiers containing two consecutive underscores (U + 005F) are reserved for use by the implementation. For example, an implementation may provide advanced keywords starting with two underscores.

Personally, I try to avoid type names with underscores, though ... I'm not sure what you mean by "replace for . ". If you could give some context, that would help.

+8
source

Yes, it is safe.

You don’t even have to think about the availability of. in the class name. I can not imagine when they will come. Perhaps if you wanted to call something ".NET," you would do with "DotNet." Class names should be concise, and I personally have never used underscores in one. I prefer camel skin.

You might consider reading MSDN - Naming Principles .

+2
source

For class names, I use CamelCasing, not _. You must adhere to one standard, this is especially important if you are working on projects with several people. The naming convention must be agreed upon within the framework of the decision / organization

+2
source

As already mentioned, it is safe. However, the Microsoft Online Naming Rules :

Do not use the underscore (_).

As John Skeet mentioned, a good alternative would be to replace . on Dot . For example, the class associated with drive.google.com might be called DriveDotGoogle . (I think that part of DotCom may be omitted so as not to unnecessarily extend the name.)

+1
source

It is safe to use _ in class names, just like with other identifiers.

Why do you need a logical one . in class names? Can you give an example?

0
source

Sounds like your CSharp generating code. If so, you can see the following helper procedure from the System.Design assembly:

http://msdn.microsoft.com/en-us/library/ms145952.aspx

 static string FixName(string givenName) { return System.Resources.Tools.StronglyTypedResourceBuilder.VerifyResourceName( givenName, new Microsoft.CSharp.CSharpCodeProvider()); } 
0
source

Source: https://habr.com/ru/post/1334604/


All Articles