|I would like to know in c# if there is any way to have 'friend' class
| just like
| in C++. I know there is the 'internal' keyword, but this will allow
| access to all
| the classes of the assembly and I want to allow access only to a
| specific class.
Not yet, but there is the...
[assembly: InternalsVisibleTo("MyFriendAssembly")]
...attribute.
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer
Carl Daniel [VC++ MVP] - 28 Jul 2006 15:06 GMT
>> I would like to know in c# if there is any way to have 'friend' class
>> just like
[quoted text clipped - 8 lines]
>
> ...attribute.
... which is a rather large hammer - a much larger hole in the type system
than friend would create. Still, if you put the class that needs a friend
into an assembly by itself, and put the class that will be it's friend into
an assembly by itself, you get nearly the effect of friend, but who'd want
to do that?
Practially speaking, you're better off putting the friends in the same
assembly and using internal and just live with the fact that all the other
classes in that assembly have more access than they need.
-cd
Maybe I misunderstand,
but if you want only one class to access it you could create it as a private
class inside that class.
Hello krishjaya,
> I would like to know in c# if there is any way to have 'friend' class
> just like
[quoted text clipped - 3 lines]
> specific class.
> if No what is the reason?