Is it safe to use _ in class names?
What's the best replacement for . in naming? (Currently I use _.)
Usually an underscore is used in member variables so as to distinguish between member variables, static member variables & local variables. This way the scope of the variable is visible in the variable name itself.
Usually underscore before a member is used when the member is private. It is usefull in language that does not have a builtin way to declare members private, like python. Show activity on this post.
Naming Conventions: Underscores. The underscore character ('_') can be used in the following situations. When naming formal parameters, it should be used as the first character. In the DEL_ prefix.
A name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice. Let’s instantiate the above class and try to access the name and _age attributes.
It's safe to do so for one underscore at a time, although you shouldn't use two consecutive underscores. From the C# language spec, section 2.4.2:
Identifiers containing two consecutive underscore characters (U+005F) are reserved for use by the implementation. For example, an implementation might provide extended keywords that begin with two underscores.
Personally I try to avoid type names with underscores anyway though... I'm not sure what you mean by "replacement for ." though. If you could give some context, that would help.
As others have mentioned, it is safe. However, Microsoft's Class Naming Guidelines read:
Do not use the underscore character (_).
As Jon Skeet mentioned, a good alternative would be to replace . with Dot.  For example, a class related to drive.google.com could be named DriveDotGoogle.  (I think the DotCom portion could be omitted so as not to unnecessarily lengthen the name.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With