- Home /
Are properties variables?
if not, can they be used as variables?
Answer by Vicarian · Oct 17, 2018 at 05:59 PM
Properties in C# without an explicit implementation (e.g.just using the keywords get and set) use an internal backing field to store data, so yes. Though properties really shine when you provide an implementation to access a backing field you specifiy yourself. For instance, you can trigger events, do validation, write logs, and introduce all sorts of other behavior by implementing the get and set methods. You can also restrict access to the set by specifiying the private or protected keywords independently of the get. If you don't intend to do any of this, for a particular field, it likely isn't necessary to use a property.
I converted your comment to an answer as this was exactly what I was going to answer.
Your answer
Follow this Question
Related Questions
Problem About Get and Set Methods 0 Answers
c# setter/getters 1 Answer
Property (set) does not work with reference c#. 1 Answer
Public variable hidden in the inspector 2 Answers
how to set a value in one script and call it in another? (c#) 1 Answer