Tag Archives: Write Better C# Code

C# Code tips

Write Better C# Code Using This Tips

I don’t know precisely what number of individuals are following coding standards. Indeed, even I was not splendidly following the coding standards. Notwithstanding, here are a portion of the coding rules that I used to take after.

To develop reusable, dependable, clear, very much organized, and maintainable application, we should take after the coding standard. There are a few coding practices in the product business. None of them are great or terrible yet the primary concern is that whatever approach we tail, we should ensure that everybody ought to take after a similar standard.

Code SmellC# Coding Using This Tips

Code Smell is a technical word used to describe the nature of code – how a developer composes this code.

Code smell is regularly a word used to describe code that you don’t care for. In that sense, it is synonymous to revolting, grimy, unclean, repeated and so forth. Despite the fact that these sorts of code work impeccably however are difficult to deal with and maintain.There are a couple of reasons why our code smells.

Duplicated Code

Techniques too huge

Classes with an excessive number of instance variables

Classes with an excessive amount of code

Lethargic Class/Freeloader

Presently, how about we perceive how we can compose clean code and maintain a strategic distance from these smells in the program. We should proceed with our talk from the fundamental coding standard, that is, on Naming Convention.

While we are coding, we should center around our naming standard. There are 2 principle sorts of naming standards that we are utilizing nowadays.

Pascal casing

A word with the main letter promoted, and the principal letter of each resulting word-part promoted.

Ex – CustomerName, EmployeeDetails, Salary,etc.

Camel casing

A word with the principal letter lowercase, and the main letter of each resulting word-part promoted.

EX – customerName, employeeDetails, pay

We should see where we will utilize which sort of casing.

Continuously utilize class name and technique name in Pascel casing.

open class EmployeeDetails

{

…….

}

Presently, this is the way we proclaim strategies inside a class.

open class EmployeeDetails

{

open void GetEmployeeSalary()

{

}

}

Continuously utilize variables and parameter names in Camel casing.

open class EmployeeDetails

{

private int totalSalary = 0;

open void GetEmployeeSalary( int employeeId)

{

int sum = 30000;

}

}

Continuously utilize letter “I” as prefix with name of interface. After letter I, utilize Pascal case.

utilizing System;

namespace cleanacode

{

interface IEmployee

{

void GetDetails();

}

}

Utilize significant variables and strategy names while coding. These names ought to act naturally distinct.

For this, I have made two examples of code. Check the main bit of code. Do you figure this code will work adequately for maintainance and code audit purposes?

open class EmployeeDetails

{

open void GetSalary(int x, int p)

{

int z = x + p;

}

}