If you use a public shared field with a public shared property, all instances of the class will point to the same memory location.
If you use a non-shared field with a not shared property, each instance of the class will store a value unique to the instance.
Here is a class example using Shared and one without:
' Class using Public, Shared fields and properties.
Public Class PersonWithSharedProperty
Private Shared mName As String
Public Shared Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
End Class
----------------------------------------------------------------------------
' Class using Public, non-Shared fields and properties.
Public Class PersonNonSharedProperty
Private mName As String
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
End Class
------------------------------------------------------------------------------------------------------
Here is some code which uses each class and explains what happens with each.
' Use a class with shared fields and properties.
Dim x As New PersonWithSharedProperty()
x.Name = "Ted"
Debug.Write(x.Name & Environment.NewLine) ' Will write Ted.
Dim y As New PersonWithSharedProperty()
y.Name = "Mary"
Debug.Write(y.Name & Environment.NewLine ' Will write Mary.
Debug.Write(x.Name & Environment.NewLine) ' Will write Mary too because a shared field and property
' were used in the PersonWithSharedProperty class.
' Use a class without shared fields and properties.
Dim a As New PersonNonSharedProperty()
a.Name = "Ted"
Debug.Write(a.Name) ' Will write Ted.
Dim b As New PersonNonSharedProperty()
b.Name = "Mary"
Debug.Write(b.Name) ' Will write Mary.
Debug.Write(a.Name) ' Will still write Ted because a shared filed and poperty were not used
' in the PersonNonSharedProperty class.
<mg********@hotmail.com> wrote in message news:11**********************@u72g2000cwu.googlegr oups.com...
Hello. I've just begun programming in VB .NET, and I'm trying to turn
all my modules into classes. In order to retrieve/exchange values from
one class to another, I initiated New instances of the classes in each
class where I needed to retrieve a property or method. I discovered
that this reciprocal loading of class instances led to stackoverflow
exceptions. I am now remedying this problem by sharing properties
among the classes. I ask you though: what's the best way to share
methods and properties reciprocally among classes? Any advice is
greatly appreciated.