C# Naming Convention

Either it’s difficult to understand the meaning or relate it with some functionality.

So let’s try to give these variables, properties and methods self-explanatory names:

If you look at the variable names here, you will see that it’s a bit lengthy, demands you to type more but now you can easily remember them and can trace its different usage across your application whenever you see these names.

That is why I am presenting the naming conventions that you can follow in C# code.

2. Don’t name your methods which is too lengthy such as:

3. Don’t use Hungarian notation in C#. Back in the days, developers following pre-fixing or suffixing data type in variable names so they don’t have to remember data type and it was popular in C++ but now latest IDEs are useful, we can hover the mouse over variable and IDE will show its days type.
So instead of having following variable names:

Change it to:

4. Avoid vague and ambiguous names.
Examples are:

This method name doesn’t specify clearly whether it’s selecting multiple items or is it processing items that were multi selected. I would have to look at it’s implementation to understand its purpose.

5. Noisy names : Don’t add extra words to variable names than required.
Examples are:

Instead make it simple as follows:

.NET follows two naming conventions :

  • camelCase

Class, property and method names must follow Pascal case and local variables, parameters, private fields must follow camelCase. Fields must also be prefixed with an underscore.

6. Poor method signature:
Try to avoid method signature that has parameter names that seem out of context and return data of different context altogether. See following code example for reference, GetCustomer is supposed to return a Customer but returns an Orange and it takes an integer airplane when in fact airplane sounds like an object.

7. Method parameters:
If your methods have repeated parameters and their count is more than 3 then think of encapsulating them in an object.

8. Out parameters:
Try to encapsulate returned data and out parameter in an object.

9. Variable declaration inside method:
Declare variable where its most likely to be used instead of always declaring it on top.




Solution developer, Workaholic

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is a “webdriver”?

SQL Monitoring Jobs

Debugging Using Radare2… and Windows!

What We Forget in Task Estimation?

Easily Share Your Twig Extensions with Symfony 6.1

Rick & Morty Lessons In Analytics

Instruments in the air using Python and Mediapipe

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AKshay Raut

AKshay Raut

Solution developer, Workaholic

More from Medium

My Teacher is a Net

Connor C

Static Libraries in C

C static libraries