How can i use the concept of friend in c#?

  • Thread starter Thread starter p
  • Start date Start date
P

p

I know the word friend is not supported in c# and its not a very good
thing to but i would be thankful if anybody can explain in simple
words how can i implement it!
 
Hello P,

Use [System.Runtime.CompilerServices.InternalsVisibleToAttribute] which allows
you to specify assemblies which have access to non-public types within the
assembly to which you apply the attribute

---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

P> I know the word friend is not supported in c# and its not a very good
P> thing to but i would be thankful if anybody can explain in simple
P> words how can i implement it!
P>
 
p said:
I know the word friend is not supported in c# and its not a very good
thing to but i would be thankful if anybody can explain in simple
words how can i implement it!

Check out 'internal'.

-- Barry
 
Kevin said:
"internal" is the C# equivalent.

Doesn't that depend on which "friend" you are talking about? I know the OP
wasn't clear. Internal is equivalent to VB Friend, but it is not equivalent
to C++ friend.

The friend access modifier in C++ allows you to be very specific as to who
your friends are. Internal in C# means simply that anyone in the assembly
can access this. Internal is similar, but not equivalent, to C++ friend.
 
Hi,

p said:
I know the word friend is not supported in c# and its not a very good
thing to but i would be thankful if anybody can explain in simple
words how can i implement it!

internal carries a similar meaning, is not the same though.

What is exactly what you need to do? Maybe we can suggest you the way to go.
 
If you mean the VB notion of 'Friend', then see the other posts ("internal").
If you mean the C++ notion of 'friend', then no equivalent exists in C#.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
I know the word friend is not supported in c# and its not a very good
thing to but i would be thankful if anybody can explain in simple
words how can i implement it!

The way we implement the "friend" concept is by making the method public,
and testing that the caller is one of a set of particular methods or
classes.

I think I don't like it, but it does do the job.

///ark
 
You're right, of course. I did not think of the C++ friend access modifier,
as I assumed (point of failure) that if the poster was asking the question,
he was a VB developer.

--
HTH,

Kevin Spencer
Microsoft MVP

Help test our new betas,
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top