+ 1
Why is the get accessor comming first?
private string name; public string Name { get { return name; } //why not set{} set { name = value; } // why not get{} //How can it return the name if the value of the name comes later?
2 Respostas
+ 2
It doesn't.
It is allowed to have set first.
It is also allowed to have get first.
Get and Set are just normal methods (yes the are dedicated). It does not matter in which order they stand.
Programmers always will do get first, so from a readability point of view you should do get first, because everybody does it.
public string Name
{
get { return name; } //why not set{}
set { name = value; } // why not get{}
}
public string SurName
{
set { surname = value; } // why not get{}
get { return surname; } //why not set{}
}
https://code.sololearn.com/cFOtA0734TIr
+ 1
thank you!