C++ type friend functionality in C#

  • Thread starter Thread starter Howard Swope
  • Start date Start date
H

Howard Swope

I keep running into places in my code where I would like only a particular
class of object to be able to access certain members of another class of
object. In C++ the friend keyword provided this functionality. The only
thing I have found in C# is internal but this is still broader in scope than
I am looking for.

Is there a way in C# to get the functionality of the C++ friend keyword?
 
Howard,

There is no way to do this in C#, internal is the best you could do in
this situation. You might be able to get around this by dividing up your
assembly into other assemblies, but this could prove to be cumbersome.

Hope this helps.
 
Sometimes it helps to use nested classes. The inner classes can access the
outer class's private members but not vice versa.
 
Yes, that would do the trick. Do you know of anyway to define the class as
nested but still have the code in another file (just to keep things clean)?
Some type of forward declaration or something like that?
 
I fear this is currently not possible.
In .NET 2.0 you have the possibility to split up classes into multiple
source files.
 

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