A Getter?

so near the end of the video he starts telling us to write the getter? i must have not been paying attention in a video because i dont recall what coding or writing a Getter means, anyone care to elaborate?

My only understanding from the video was that instead of making the list public he made a method of the list that can call it or get it?

Hi Jayy,

We are trying to followthe OOP principles and don’t want to make our variables accessible for other instances because that would make our program prone to errors.

For this reason, we write Get methods that return a value, a new object or an object reference.

In C#, there is something called properties. That’s where the term “getter” comes from. We cannot use the [SerializeField] with properties. We need a normal variable for that. The easiest way to stick with the OOP principles is to create a Get method. Alternatively, we could create an actual getter with a property returning the value of the private variable. That’s a matter of taste, though.


See also:

1 Like

Thank you.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms