Santosh Poojari Santosh Poojari - 1 year ago 87
C# Question

Can we have class name with alphanumeric character?

Can we name class using alphanumeric values ?like class Tier1, Tier2 and so on.Is this come under good practice. What is the recommendation around naming class. I know this is very generic question and simple one however there were instance during code review I often came across class names which seems to be usual.

Answer Source

You should read Microsoft Coding Guidelines here:

The naming guidelines that follow apply to general type naming.

✓ DO name classes and structs with nouns or noun phrases, using PascalCasing.

This distinguishes type names from methods, which are named with verb phrases.

✓ DO name interfaces with adjective phrases, or occasionally with nouns or noun phrases.

Nouns and noun phrases should be used rarely and they might indicate that the type should be an abstract class, and not an interface.

X DO NOT give class names a prefix (e.g., "C").

✓ CONSIDER ending the name of derived classes with the name of the base class.

This is very readable and explains the relationship clearly. Some examples of this in code are: ArgumentOutOfRangeException, which is a kind of Exception, and SerializableAttribute, which is a kind of Attribute. However, it is important to use reasonable judgment in applying this guideline; for example, the Button class is a kind of Control event, although Control doesn’t appear in its name.

✓ DO prefix interface names with the letter I, to indicate that the type is an interface.

For example, IComponent (descriptive noun), ICustomAttributeProvider (noun phrase), and IPersistable (adjective) are appropriate interface names. As with other type names, avoid abbreviations.

✓ DO ensure that the names differ only by the "I" prefix on the interface name when you are defining a class–interface pair where the class is a standard implementation of the interface.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download