On Wednesday, 11 April 2018 at 17:34:40 UTC, bauss wrote:
On Wednesday, 11 April 2018 at 17:20:23 UTC, martin wrote:
On Monday, 9 April 2018 at 17:16:56 UTC, bauss wrote:
On Monday, 9 April 2018 at 17:05:45 UTC, martin wrote:>>
Actually, this behaves as i would expect.
`_baz` is a private member of Foo (to be precise: it belongs to module `a`)
in handleBar(), you iterate `Bar[]` - which is in module `b`.
By casting it to Foo, you are accessing the wanted module (`a`) again.

but handleBar() is in a.

This behavior is allowed in ex. C#

`_baz` is a member of `module a : Foo` - `_baz`, as is `handleBar()`.
`protected` is the Access specifier you want.
If i understand you correctly, you want it to behave as if `_baz` would be a member of `handleBar()`

If this is really possible in C#, it lets my eyebrow raise.

Execute the following C# program and it will work just fine:

It's a really common pattern with OOP.

public class Foo
        private string _baz;
        public void HandleBar(Bar bar)
                bar._baz = "Hello";

public class Bar : Foo


var bar = new Bar();

Also protected is not the access modifier I want.

I only want to set it through the parent class and it should only be used within the parent class.

But it's on each child passed to the parent class that it's set.

The children should NEVER touch the variable.

Reply via email to