Why not Private Set public get?

Been wondering throughout the course why you’re always using methods for exposing properties instead of private set, public get. IE:

        private bool _isEnemy;
        public bool IsEnemy() => _isEnemy;

Is there a reason why you chose to do a method getter, instead of a private set, public get property?

     public bool IsEnemy => _isEnemy;
2 Likes

Mainly personal preference. Personally I am not a fan of using properties for anything other than the singleton pattern. I find that they confuse the code by looking like variables but acting like functions so I much prefer to use a very clear Get() function.
But the end result is the same so if you like properties then go ahead and use that method.

4 Likes

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

Privacy & Terms