Naming of variables, functions and classes in CSharp
In this article we are going to cover naming conventions of variables, functions and classes in CSharp. Hereby some of the covered content is mandatory, others are just conventions which should be complied with. Every person is different, and every programer has his own style of naming variables. In order to make code as readable as possible, those conventions came into play.
- (convention) Variable names and functions should be written lower case, classes upper case. Hereby it is really important to comply with this, as otherwise in more complex code the readablity becomes a nightmare. Knowing that if something is written upper case, it is a class makes things easier.
- (Rule) No special characters allowed! You cannot use special characters in neither variables, functions nor classes. Trying to do so results in an error in your code and will not be accepted by your compiler. Try it in Visual Studio and see for yourself 😀
- (Rule) No numbers at the beginning of the variable name. You can use numbers within the name, but not at the beginning.
Example: value1( works), w3p (works), 3gp (doesn’t work)
A helpful way to name Variables or Functions consisting of more than one word is to use a capital letter for the first letter of the next word (not for the first though).
E.g. myAgeVariable = 28;
This way it is easier to understand what the variable is all about.
When ever working with an international team it is advised to use english variable names only.
We will cover more aspects of the naming convetions throughout the course, as soon as we get there.