Introduction
This article helps you to know about the best coding practices that are used while coding using C# language. When we deliver code the created code should follow some standard which will improve optimization, readability, and quicker action on code that also improves the security aspects of code.
C# Coding Guidelines
Please find the review guidelines, as follows,
Standards
This is basically suggested for all developers, code can be revisited or maintained by any developer so many times it's good to follow the basic standards like proper File name, class name and method name.
Naming Conventions
The Name you have given for all above class, method, variable etc. should have proper naming standards and meaningful information.
Pascal Casing
First characters of all words are Upper Case and other characters are lower case.

Camel Casing
First characters of all words, except the first word are Upper Case and other characters are lower case.

Check for 'null'
Where ever there is possible for Null occurrence, make an explicit null check, this avoid the execution error.

Remove Unused Using’s
Using statement will load all the assemblies, so it’s better to remove unwanted assembly namespace reference in the codes.

Indentation and Spacing
It is recommended to use TAB space than a white space and this helps for better code readability. Use single space between two lines of codes and two lines between methods.

Comment Lines
It is always good to use the comments lines for each class, methods and some logic which is complex for a reader to understand.

Code Reusability
Try to use the available code and use the concepts like Generics to avoid repetitive codes.

Project Warnings
Always avoid project warning, which will help hackers to find a path to get into your code and break the applications.

Modularity of Code
Avoid writing very long methods. Mostly method should typically have approximately 1~25 lines of code.
If a method has more than 25 lines of code, you must consider re-factoring into separate methods and this is called modularization of code.
As discussed in naming standard, the method name should tell what it does. Do not use misleading names. If the method name is obvious, there is no need of documentation explaining what the method does explicitly.

Hard codes
Avoid Hard codes, when a part of value is hard coded in the application, which is not easy to modify the code whenever required; to modify such values again the application should be deployed.
Sometimes the hard coded values may affect the actual logic of application behavior.

Config Values
If any of the values are required to be modified frequently or occasionally then it is recommended to have the values stored in the configuration files rather than storing it in any of the application objects and these value modifications do not require the application restart or deployment only the update in config file is fine.

String Comparison
When there is any scenario to compare any of the string values, it is always better to convert the string to lower case or upper case and then compare both the string values.

String Declaration
It is always suggested to declare the string value with “string.Empty” value than the “” empty values between double quotes.

Usage of Enum
We have the special data type called “enum” in C#, it’s strongly recommended to use the enum data type whereever required instead of using the string or integer to indicate discrete values.

Note: We have more guidelines to be discussed, soon expect the next part of coding guidelines.

Vladimir BicikPosted Jun 22, 2017, 1:55 AM
Hello, when string comparing depends on casing, better use static String.Equals with right StringComparison parameter
jalpesh vadgamaPosted Jun 21, 2017, 10:06 AM
An int can not be null in c#. It always zeroes so put int? if you want to make it nullable.
Zahid MustafaPosted Jun 21, 2017, 6:59 AM
Check for 'null' Its not correct because parameter is not nullable
Sivaiah DevaraPosted Mar 18, 2017, 1:54 PM
Nice article, thanks
Mariusz SzPosted Dec 1, 2016, 8:38 AM
It's good to say when and where use Pascal or Camel style
Shamim UddinPosted Oct 12, 2016, 1:54 AM
Nice article
Saurabh SarkarPosted Jul 21, 2016, 9:20 AM
Nice article
Bhuvanesh MohankumarPosted Jun 25, 2016, 2:33 PM
Thanks Prasanna M
Bhuvanesh MohankumarPosted Jun 25, 2016, 2:33 PM
Thanks Raja Ganapathy
Bhuvanesh MohankumarPosted Jun 25, 2016, 2:33 PM
Thanks Farhan Shariff
Bhuvanesh MohankumarPosted Jun 25, 2016, 2:33 PM
Thanks Anish kumar
Bhuvanesh MohankumarPosted Jun 25, 2016, 2:33 PM
Thanks Anu Vivin
Prasanna MuraliPosted Jun 21, 2016, 9:42 PM
Nice one
RajaPosted Jun 6, 2016, 2:37 AM
Nice Article...
Farhan ShariffPosted Jun 5, 2016, 8:13 PM
useful articl
Anish KumarPosted Jun 4, 2016, 11:07 AM
Nice article , very usefull...
Anu VPosted Jun 3, 2016, 7:30 AM
Nice
Bhuvanesh MohankumarPosted Jun 2, 2016, 5:10 AM
Thanks Anand More
Bhuvanesh MohankumarPosted Jun 2, 2016, 5:10 AM
Thanks Prasham Sabadra
Bhuvanesh MohankumarPosted Jun 2, 2016, 5:10 AM
Thanks Rupali Shinde
Bhuvanesh MohankumarPosted Jun 2, 2016, 5:09 AM
Thanks Mohammed Ashraf
Bhuvanesh MohankumarPosted Jun 2, 2016, 5:09 AM
Thanks @Anand mor
Prasham SabadraPosted May 31, 2016, 6:51 AM
Thanks for Sharing!!!
Rupali ShindePosted May 30, 2016, 8:11 AM
really useful tips for developer :) thanks for sharing ..
Mohammed AshrafPosted May 30, 2016, 3:29 AM
Really informative...
Anand MorePosted May 30, 2016, 2:25 AM
Thanks for sharing Bhuvanesh !!
Bhuvanesh MohankumarPosted May 29, 2016, 9:48 AM
Thanks Viipiin Tyagi
Bhuvanesh MohankumarPosted May 29, 2016, 9:47 AM
Thanks & its Just Microsoft Paint Prakash Tripathi
Bhuvanesh MohankumarPosted May 29, 2016, 9:47 AM
Thanks for that @Abhishek Sur
Vipin TyagiPosted May 27, 2016, 9:25 AM
It's a great article.
Prakash TripathiPosted May 26, 2016, 4:22 AM
Good one Bhuvanesh....Just curious which tool you used to draw the pictures for do/don't?
Abhishek SurPosted May 25, 2016, 12:37 PM
One small adjustment : Null can only be checked when it is nullable. If not it will already have default(type). Another thing string s = ""; and string s = string.Empty will have same meaning as because empty string is always interned in .NET. Also accountName.Equals("bhuvan", StringComparison.CurrentCultureIgnoreCase) will ignore the creation of extra Upper case string in memory.
Bhuvanesh MohankumarPosted May 23, 2016, 3:41 AM
Thanks Pratik BHAVSAR
Pratik BHAVSARPosted May 22, 2016, 5:33 PM
nice article
Bhuvanesh MohankumarPosted May 22, 2016, 12:28 PM
Thanks Jeff Orris
Bhuvanesh MohankumarPosted May 22, 2016, 12:28 PM
Thanks Sabyasachi Mishra
Jeff OrrisPosted May 22, 2016, 10:41 AM
I love your guys' site...anytime I need refreshed or to keep my coding in check I turn to you....you make it so easy for others to understand.
Sabyasachi MishraPosted May 20, 2016, 12:19 AM
Good one
Bhuvanesh MohankumarPosted May 17, 2016, 2:14 PM
Thanks Pradeep Sahoo
Bhuvanesh MohankumarPosted May 17, 2016, 2:14 PM
Thanks Sonu Chaudhary
Bhuvanesh MohankumarPosted May 17, 2016, 2:13 PM
Thanks Rambabu Chintapanti
Bhuvanesh MohankumarPosted May 17, 2016, 2:13 PM
Thanks Rajeesh Menoth
Bhuvanesh MohankumarPosted May 17, 2016, 2:13 PM
Thanks Ipsita Sethi
Pradeep SahooPosted May 15, 2016, 11:12 PM
Nice information .Thanks for sharing.
Sonu ChaudharyPosted May 12, 2016, 11:30 AM
nice
Rambabu ChintapantiPosted May 12, 2016, 12:49 AM
Nice Article
Rajeesh MenothPosted May 11, 2016, 10:46 PM
Good Explanation..Thank you for sharing!! We can use enum for hard coding area's.
Ipsita SethiPosted May 11, 2016, 1:32 PM
Nice sharing Bhuvan
Bhuvanesh MohankumarPosted May 11, 2016, 12:58 PM
Thanks, I have mentioned in early comments itself. " Yes of course its just for some sample, instead of a class mentioned as int".
Bhuvanesh MohankumarPosted May 11, 2016, 12:57 PM
Thanks @Paramjit Singh
Bhuvanesh MohankumarPosted May 11, 2016, 12:56 PM
Thanks @Jitendra Kumar
Jitendra KumarPosted May 11, 2016, 8:08 AM
Nice Article..
Paramjit SinghPosted May 11, 2016, 6:11 AM
Yes Right not necessary. But if you want to check null also then apply nullable, before check. in case of int.
Vladimir BicikPosted May 11, 2016, 3:08 AM
Null test on "int value" is not necessary. Do you mean "int? value" ?
sachith wickramaarachchiPosted May 10, 2016, 1:47 PM
Awesome post,really helpfull
Paramjit SinghPosted May 10, 2016, 10:32 AM
Good one
Paramjit SinghPosted May 10, 2016, 10:30 AM
In null Check If we apply nullable like this public string GetDate(int? value) Then we can check it null. isn't it
Abhinav AbhishekPosted May 10, 2016, 6:15 AM
Thanks for sharing
Manish Kumar ChoudharyPosted May 10, 2016, 3:22 AM
Nice one.
Vishal PatelPosted May 10, 2016, 1:29 AM
nice one
Muhammad Aqib ShehzadPosted May 9, 2016, 11:57 PM
Very Nice article
Kishor Bikram OliPosted May 9, 2016, 9:12 PM
Nice really helpful. Thanks
Luis OrozcoPosted May 9, 2016, 7:58 PM
Nice article :)
Munesh SharmaPosted May 9, 2016, 12:37 PM
nice article
Kuppurasu NagarajPosted May 9, 2016, 12:00 PM
Nice Sharing..
Guest UserPosted May 9, 2016, 11:26 AM
I liked the article! Good points, looking fwd for part 2
Vincent Maverick DuranoPosted May 9, 2016, 6:10 AM
You should indicate when to use Camel or Pascal casing. It would be also helpful if you will add using underscore when naming global variables. Second, int a is value type and it requires a value so it doesn't make sense to check for nulls on int type not unless if you declare it as nullable type of int. Third, commenting isn't necessary for as long as you name your method properly. For example GetData() is not helpful and meaningful, GetCustomerOrderByID() is. Making your method name meaningful helps you easily understand what the code is all about and there's no need to put comments on it not unless if the logic within it has complex implementation.
Soumik MukhopadhyayPosted May 9, 2016, 5:02 AM
Good Tips
Vineet KumarPosted May 9, 2016, 4:21 AM
String str = "" and string str = String.Empty. What difference does it make? Why is it better to use string.Empty
Vineet KumarPosted May 9, 2016, 4:19 AM
String Comparison -- We should instead use, String.Compare with ignorecase option.
Vineet KumarPosted May 9, 2016, 4:19 AM
Nice article
Cătălin RădoiPosted May 9, 2016, 3:01 AM
Great article! Every new employee should read and sign something like this :) p.s.:I don't believe that an int can be null
Hari ShankerPosted May 9, 2016, 1:05 AM
Thanks Nice Article
Former memberPosted May 9, 2016, 12:35 AM
Good one
Sandeep Singh ShekhawatPosted May 9, 2016, 12:17 AM
Good one, I just want to add that enum must be in separate file and must have a value for each such as public enum LoginType:byte{Admin = 1,Member=2 }
Prakash TripathiPosted May 8, 2016, 6:42 AM
Good one Bhuvanesh.
Pankaj Kumar ChoudharyPosted May 8, 2016, 4:18 AM
Nice Efforts Sir......