Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Common Conventions for Writing Code in C#

    • 0
    • 1
    • 1
    • 3
    • 0
    • 0
    • 0
    • 0
    • 665
    Comment on it

    Except from the rules which C# compiler enforces, there are common conventions for writing code in appropriate way.

    If we use these conventions, it will make our program consistent and easy to read for others.

    Although for compiler, it doesnt matter how you write your code as long as you follow the rules enforced by compiler which is language specific.


    • We should type names for classes, structs, and methods in Pascal casing, which basically means that they should start with a capital letter. If the name consists of multiple words which are joined together, then we capitalize the beginning of each word (for example, MyCustomClass and MyAccountInformation).

    • We should start the name of the interface with the capital letter I (for example, ICustomInterface and IInterfaceOne).

      
    • If we are declaring a local variables, then we must use camel case, which means that the name starts with a lowercase letter and the first letter of each successive word is capitalized (for example, customVariable, myInt, and CustomDoubleTypeVariable).


    • Use names which are more or less expressive that convey the meaning or their use, such as myAccountNumber and myPhoneNumber. Names like a, b and c should be avoided unless we are using it in the proper context, like mathematical equations or coordinates.


    • We should start the left brace ({) on a next line under the class or class member declaration. The right brace (}) must be placed in the same column on a separate line.

      For example:

      class CustomWorld 
      {
       // class body 
      } 
      

      Notice that the class body starts in the fourth column after the left brace (indented by three spaces).


    • We should leave a blank line after each distinct operation, such as after new variable declarations, repetition of loops, or any conditional constructs. This will make our code much more readable any understandable for other users.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: