C# - Naming Standards

Coding Standards for C#: Names

Why Coding Standards

Simple: maintainability. If, 6 months down the line, your customer isn't too happy with the product and wants an enhancement in the application you have created, you should be able to do it without introducing new bugs. There are a lot of other good reasons, but this is the one which concerns us more than anything else.

Not following any standard is like going with a temporary solution (which might lead to a permanent problem) and, as you will see, it takes less effort to keep in mind a few simple measures than to do haphazard coding.

All you have to do is study good standards once and keep them in the back of your head. Trust me; it's worth it.

Contents

Naming - What is meant by meaningful names

Casing - When to use PascalCase and when camelCase

Generics - Proper usage

Delegates - Proper usage

Miscellaneous - Some short tidbits

Common Pitfalls - Mistakes we should watch out for

References - Where to get more information

Naming

"The beginning of wisdom is to call things by their right names" - Chinese Proverb

"Meaningful" is the keyword in naming. By meaningful names, I mean concise names that accurately describe the variable, method or object. Let's see how this would be in C#:

Namespaces - Names should be meaningful and complete. Indicate your company or name, product and then your utility. Do not abbreviate.

Comments and Discussions

The check for a different returnValue is never true since the only place where the value gets changed, it isn't changed and then is followed immediately by a <font color="0000ff">return</font> statement.