C# Coding Standards, Best Practices & Visual Studio Tips

                  Anybody can write a “Working Code” but to write “Efficient Code” you have to read loads of books, know the internet, and have some years of experience. These standards derive from the experience of product development efforts and are continuously evolving. I‘ve just compiled this article from books/internet and someone’s experience. This article is not the Bible, as we must keep updating our knowledge and learning. By applying a set of well-defined coding standards our in the code will have fewer bugs and better maintainability. The efficient code should be:
  • Easily understandable
  • Maintainable
  • Efficient
Important Note: The naming conventions and best practices described in this article are compiled from our own experience and by referring to various guidelines.

Purpose :

To develop a reliable and sustainable application, you must follow coding standards. Several standards exist in the programming industry. None are wrong or bad. It is important to select one standard approach and ensure that everyone follows it.
  • Improvements to C# that were made in its 6th version.
  • LINQ in .NET framework.
  • Asynchronous programming and objectTask in C#.
  • Unsafe programming in C#, which allows you to go into memory management stuff.
  • Object initialization.
  • Null checkup.
  • String building in C#Looping over a large collection of data.
  • Avoid unsafe context.
  • Use lambda expressions where possible.
  • Static Members.
  • LINQ Queries

  • Visual Studio Tips :

    • <CTRL><K><D> formats the current document.
    • <CTRL><]> navigates to the matching bracket.
    • If you put the cursor on a line of code and use the <ALT><UP ARROW> key the line of code you have selected moves up. If you use the <ALT><DOWN ARROW> the line of code selected moves down.
    • If you select a piece of code and then use the key sequence <CTRL><M><H> you turn that region into a collapsible/expandable region. The key sequence <CTRL><M><U> will remove the collapsible region (it doesn’t delete the code, it just removes the icon that allows you to expand and collapse).
    • F12 key or the pop-up menu option Go To Definition helps the programmer to examine code into the method. Sometimes, you just want a quick look at the method. If you have installed Visual Studio 2013 there is a new keyboard shortcut <ALT><F12>, which will give you a preview of the method being called inline. You can use the <ESC> key to close the preview.
    • When you have multiple files open at the same time you may want a way to quickly move back and forth between two or three different locations in your code. If you have moved from one location to another you can use the keyboard sequence <CTRL><-> to move to the previous location and then you can return using <CTRL><SHIFT><->.
    • You can switch between Visual Studio opened tabs by <CTRL> <TAB> and <CTRL><SHIFT><TAB>.
    • EDIT à Navigate or <CTRL><,> feature in Visual Studio allows you to quickly find your required files and symbols.
    • <SHIFT><ALT><ENTER> to view code editor in Full Screen.
    • Visual Studio has the facility of built-in code snippets and many more shortcuts in VIEW and last segment of EDIT menu.

    Final words:

    This is a post where you can find a few of the tips that can help you in making the most of your C# applications using best (or at least better) ways to write your C# programs and in which, the performance can also be fine-tuned. If you have more, let me know I would love to hear them out. :-)

    Comments

    Popular Posts