Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2006

Tip: Looking for answers? Try searching our database.

friend class in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
krishjaya - 28 Jul 2006 11:24 GMT
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?
Joanna Carter [TeamB] - 28 Jul 2006 11:42 GMT
|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
Sandeep - 01 Aug 2006 14:00 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.