✅ get set help
i dont understand the application of a get set method. are there any practical examples you can give?
4 Replies
in C# we don't use get and set methods, we use properties that accomplish the same thing
basically, the reason to use them is that so the class has full control over its data
for example, maybe you don't want outside the class to change the value in which case you'd make the setter private
or you want to do some validation of the value
ah, so another class can reference
MyProperty
and that gives the value of _myField
yes, but the class that contains MyProperty has control over what other classes can change the value to
since it has to go through the setter
or if you wanted to change the value to be calculated by some other process, you can change that inside the class without other classes needing to know or be updated
thank you discord user amogus jimmacle
i understand better now