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();
bar.HandleBar(bar);

Reply via email to