Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Friend vs Shared access modifier!

Status
Not open for further replies.

fixthebug2003

Programmer
Oct 20, 2003
294
US
Hi,
Can someone point out the difference between Frien and Shared acess modifiers?

Fixthebug2003
 
[tt]Shared[/tt] is not an access modifier. It's a keyword indicating that the declared Sub, Function, Property, Variable, etc. are not at the instance level, but at the class level. It doesn't change who is allowed to access the item in any way.

[tt]Friend[/tt] is an access modifier that indicates that only in the program in which the item is declared, or the same assembly, is it accessible.

 
Friend members are visible throughout the project. Anything declared Friend is visible through the project, but not from other projects

Shared Members can be referenced across projects without creating an object Instance. But code in Shared members cannot access non shared members within its own class.

Shared fields or properties are equivalent to global variables. Change it for one instance of the class and it is changed for all instances.

Basically Shared is PUBLIC, and Friend is somewhere between PUBLIC and PRIVATE.

Phew....hard to explain, but hope that helps.

Sweep
...if it works dont mess with it
 
Assuming that you have Visual Studio with the MSDN Help, press the Dynamic Help Tab, press the Index icon in Dynamic Help, set "filtered By" to Visual Basic, then enter "shared keyword" in "Look For". Did you know that there is a Shared Constructor, i.e. Shared Sub New()?

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top