C# Coding Standards and Best Programming Practice Part-1

March 26, 2013 // In: C#


Software Engineering is a team activity where every individual is playing a vital role. Most successful software projects are granted for team players and not individual efforts. Purpose of this article is to familiarize developers involved to keep few things in mind while they are developing the product. It will help you in the project as well as improve your team abilities for future. We will focus on developers to agree on a standard and follow it through the software development.

coding standards and programming practice


Following list describes areas or things that we need to take care of while developing softwares.

1. XML Comments

Always use XML comments for each major block of code. We don’t focus to write comment on every line of program. But only on the major block of code like if you are developing a class, then first add comment with class. Secondly add comments on the public methods or members of class. An example of this is as

2. Avoid Using Constants or Magic Numbers

Avoid using constants or magic numbers in the program.  For constants define Enums there and use them. See below example.

Here rather than using constants you can use enum throughout the program.

3. Use Configuration Manager

Never use/access configuration files settings directly or you can say use of configuration manager on the forms or pages you develop is not good practice. For thisyou can add a class “AppSettings”. In this class you can define your own constants and populate them from the configuration file. See below snap code for this.

 4. Constants

Make constants with upper case letter like in above example.

5. Keep Track of Warnings

Keep track of the warnings as well while developing. This will suggest you many things regarding your code. For example if you define a variable and don’t use in code, you will get a warning regarding this. By doing this you will remove un necessary code/variables from the file.

6. Use of foreach Loop

For collections try your best to use “foreach” like loops and not the traditional for or while loops.

7. Empty Strings

Empty string comparison or assignment is not appreciated through (“”), but instead use the string.Empty. You will mostly need this on clearing the form controls.

8. Exception Handling

Your code should use exception handling and give proper messages to user.

9. Use Methods

Don’t write code directly in the form control events, instead make your own functions/methods and call them from your events as required.

10. Hot Keys

Make your form controls user friendly and useable through keyboard. For this use hot keys and accelerator keys.

C# Coding Standards and Best Programming Practice Part-2
Run Application in Administrator Mode in VS2010
  • danielgrant

    Old information during the look for engine market is like generating close to with unclean oil. bean bags