473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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!

Mar 8 '07 #1
9 1650
Hello P,

Use [System.Runtime.CompilerServices.InternalsVisibleTo Attribute] 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

PI know the word friend is not supported in c# and its not a very good
Pthing to but i would be thankful if anybody can explain in simple
Pwords how can i implement it!
P>
Mar 8 '07 #2
"internal" is the C# equivalent.

--
HTH,

Kevin Spencer
Microsoft MVP

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

"p" <na******@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>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!

Mar 8 '07 #3
p wrote:
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

--
http://barrkel.blogspot.com/
Mar 8 '07 #4
"p" <na******@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>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!
http://www.thescripts.com/forum/thread235353.html

This is a superb reference site for such matters:
http://www.dnzone.com/ShowDetail.asp?NewsId=356
Mar 8 '07 #5
Kevin Spencer wrote:
"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.
--
Tom Porterfield

Mar 8 '07 #6
Hi,

"p" <na******@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>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.
--
Ignacio Machin
machin AT laceupsolutions com
Mar 8 '07 #7
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
"Michael Nemtsev" wrote:
Hello P,

Use [System.Runtime.CompilerServices.InternalsVisibleTo Attribute] 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

PI know the word friend is not supported in c# and its not a very good
Pthing to but i would be thankful if anybody can explain in simple
Pwords how can i implement it!
P>
Mar 8 '07 #8
"p" <na******@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>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
Mar 8 '07 #9
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

"Tom Porterfield" <tp******@mvps.orgwrote in message
news:ed**************@TK2MSFTNGP05.phx.gbl...
Kevin Spencer wrote:
>"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.
--
Tom Porterfield

Mar 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Alfonso Morra | last post by:
Hi, I've written a very simple Simpleton design pattern class template. This was supposed to illustrate a point. Although it compiles without nay errors, I get link errors (unresolved external),...
8
by: Bruce D | last post by:
I'm developing my first VB.NET application and I want to use good coding technique, but I'm a little confused about 'modules and 'classes'. I have several windows forms that have to connect to my...
4
by: Madhav | last post by:
Hi all, I am a newbie in c++. I want to know what is the philosophical reason behind the existence of friend functions. I thought giving access to private data to a function which is not a member...
9
by: Adam Badura | last post by:
I have code like this template<int size> big_int { /* ... */ template<int size2> friend class big_int<size2>; }; What I wanted to achive is to be able to easly convert different sized...
2
dmjpro
by: dmjpro | last post by:
actually i working with JSP. but yesterday a friend was working with servlet. there a Q. arised. that is ...... if my servlet class extends HttpServlet class then if i leave all doGet and doPost...
5
by: tuananh87vn | last post by:
hi, I'mm writing script for adding friend to a friend list.i'm using a form including friend_name (text), message (textarea) and below is my code: if(isset($_POST)) { ...
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.