Living .NET...

Musings on .NET, and the like - Manoj G [MVP, Connected Systems Developer]

A "Friend" in need....

Well, I am talking about the "Friend" access specifier of VB.NET here.
 
Honestly, I am not comfortable with keyword Friend and its actual semantics in VB. A Friend member is something that can be seen only within an assembly. That's it - it does not promise any more. In C++, a friend is something that can peep into your object's private members.

I think that is the reason why it is called by a more intuitive "internal" in C#. I agree, this was the way Friends worked in VB6 and hence the same semantics. 

Okay now, to a lesser know (& interesting) fact about Friends. Try this:

1. Create a class and have Friend as its access qualifier.
2. Derive a class from the above and have Public as its access qualifier.

Our humble compiler would disallow the same. Can you explain why our man was unhappy here ? Quite logical. If the above case were to be allowed, then public derived class would serve as windows to the hidden internal types. This would be a sort of access violation and hence this behavior makes sense.

Signing off with "Friendly" regards...

Posted: Jan 14 2004, 10:51 AM by Manoj G | with no comments
Filed under:
Leave a Comment

(required) 

(required) 

(optional)

(required)