Shared Keyword


Shared Keyword

Description

The Shared keyword indicates that a type member is a shared member instead of an instance member. Shared members are available without creating an instance of the type; instance members can only be used through an instance. Consider the following simple class:

     Friend Class ClassForSharing        Public Shared sharedValue As Integer        Public unsharedValue As Integer     End Class 

The following code block shows how to access each member.

     Dim realInstance As New ClassForSharing     ClassForSharing.sharedValue = 5     realInstance.unsharedValue = 10 

Shared members are indirectly shared among all instances of the class, even though they exist apart from all instances.

The Shared keyword can be used with the following statements:

Dim Statement
Event Statement
Function Statement
Operator Statement
Property Statement
Sub Statement

By default, all of these members are instance members unless qualified with the Shared keyword.

See Also

For the statements listed above, see the related entries elsewhere in this chapter for usage information.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net