C# getter setter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# getter setter

In C# codes, it's write : get { return varName; } set { varName = value; } why the "get" is before the "set" if we set the value first (with set) and then return it (with get) ?

15th Dec 2016, 2:33 PM
Mocking Bird
Mocking Bird - avatar
2 Answers
+ 3
It doesn't matter which is before which. If you want to GET the value, GET is called. If you want to SET the value, SET is called. Order doesn't matter.
15th Dec 2016, 2:40 PM
Uran Kajtazaj
Uran Kajtazaj - avatar
0
Thank you, now I get it
15th Dec 2016, 7:05 PM
Mocking Bird
Mocking Bird - avatar