Quote:
|
But I can't figure out how to put the two techniques together to control access to the private fields of an array of objects.
|
You cannot access private members of an object outside of its class. That's the purpose of the "private" access modifier. You can only use the "this" keyword within an instance method or instance property of some class. When you do use it, it allows access
only to any member defined on the class in which you are using it. Technically, you don't have to use it at all, since any method or property you call without specifying an object will implicitly use "this".
Think of it this way: Any instance method or property you call has to be executed on some object. If you want to call the "Name" property on an instance of your Citizen class, you do it like so -- citizenInstance.Name. You seem to understand that concept. However, if you want to call a method from a different method on the same object, you can use the "this" keyword or just specify the name of the target method without using "this".