|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
friend class in c#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. if No what is the reason? "krishjaya" <krishj***@hotmail.com> a écrit dans le message de news: 1154082256.933580.156***@s13g2000cwa.googlegroups.com...|I would like to know in c# if there is any way to have 'friend' class Not yet, but there is the...| 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. [assembly: InternalsVisibleTo("MyFriendAssembly")] ....attribute. Joanna -- Joanna Carter [TeamB] Consultant Software Engineer Joanna Carter [TeamB] wrote:
Show quote > "krishjaya" <krishj***@hotmail.com> a écrit dans le message de news: .... which is a rather large hammer - a much larger hole in the type system > 1154082256.933580.156***@s13g2000cwa.googlegroups.com... > >> 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. 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, Show quote > 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. > if No what is the reason? > |
|||||||||||||||||||||||