Why is the get accessor comming first? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

30th Jan 2019, 4:15 PM
Mike Willems
Mike Willems - avatar
2 Answers
+ 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
30th Jan 2019, 9:24 PM
sneeze
sneeze - avatar
+ 1
thank you!
31st Jan 2019, 4:24 PM
Mike Willems
Mike Willems - avatar