Public vs Friend

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables?
 
I have used it for controls and such.

Lets say you have a module wth code that needs to be public for other member
of your project, but you want it to be hidden from the end user. Declare it
Friend. If you want it to be accessed for everything then declare it
public.

I haven't found many times for the need, but does arise. For another
instance. I made a message box control that had 3 forms. I needed a class
to interact with the forms, but I didn't want a user to grab the forms, so I
made them friend classes.

Hope that help a little

Dennis said:
I have read and re-read VB.Net's help on scope of variables but darned if
I can understand the difference between Friend and Public variables?
 
I think I understand. Public class1 lets me access class1 in my assembly as well as other users who add my assembly to their projects. If I use Friend, then I can access class 1 in my assembly but others using the assembly in their projects cannot access class1. Thanks.
 
friend vars are available to other members of the same package (i mean same
Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace

Java calls it package
VB calls it Namespace


Dennis said:
I have read and re-read VB.Net's help on scope of variables but darned if
I can understand the difference between Friend and Public variables?
 
Hal Rosser said:
friend vars are available to other members of the same package
(i mean same Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace

Would that that were True.

In my experience, "Friend" only exposes stuff within the current
/Assembly/, and /not/, as I would /dearly/ like, the given Namespace!

Regards,
Phill W.
 

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