When you name a method, it is good to use meaningful names. Because every method handles a part of our problem, when naming it we should keep in mind the action it does, i.e. it is a good practice for the name to describe what the method does.
In C# the method name must start with uppercase letter and should be made of a verb or a couple: verb + noun. The name is formatted by following the Upper Camel Case convention (PascalCase), i.e. each word, including the first one, starts with uppercase. The brackets
) always follow the name.
Each method must do one task and its name should describe this task.
A few examples for correctly named methods:
A few examples for incorrectly naming our methods:
If you cannot think of an appropriate name, then the method most probably solves more than one task or doesn't have a clearly defined purpose and in this case you have to think how to divide it in several simpler methods.
When naming the parameters of a method you can apply almost the same rules as with the methods themselves. The difference here is that it is good for the names of the parameters to use a noun or a couple of an adjective and a noun, and when naming the parameters, we use the
lowerCamelCase convention, i.e. each word except for the first one starts with uppercase. We should note that it is a good practice that the name of the parameter shows what unit is used when working with it.
A few examples for correctly named parameters:
A few examples for incorrectly named parameters: