We are following the/a C# naming convention. This “requires” us to have classnames start with a capital letter.
public class Person
{
}
And the variables inside the class usually start with a minuscule letter, except for the primitive types and the three built-in reference types string
, object
and dynamic
.
public class Person
{
string name;
string role;
int age;
Person mother;
Person father;
Person[] siblings;
}
In C#, the syntax for the declaration of a variable is:
accessModifier classname/type variableName;
We have a Timer class, so a variable of type Timer must be declared as:
Timer timer;
Timer myTimer;
Timer anotherTimer;
// with an access modifier
public Timer timer1;
private Timer timer2; // private is the default access modifier
A convention means that a group of people tend to follow these rules. The compiler does not care if you have your classnames start with a minuscule letter.
class person
{
string name;
string role;
int age;
person mother;
person father;
person[] siblings;
person[] Friends;
}
That’s valid C# code but “bad practice” because it contradicts the majority of the C# naming conventions. It makes understanding the code difficult as it goes against the expectations.