Monday, 16 August 2010

Difference between [Shared Function/Sub] V.S. [Function/Sub]

So if I am to create a class, what should I consider when deciding whether to make a method shared or not? Both ways seem to be capable of doing the same thing.
Code:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

'shared member
txtShared.Text = SharedTest.ReturnString

'non shared member
Dim NST As New NOTSharedTest
txtNotShared.Text = NST.ReturnString
End Sub

End Class

Class SharedTest

Shared Function ReturnString() As String
Return "I am Shared"
End Function

End Class


Class NOTSharedTest

Function ReturnString() As String
Return "I am not Shared"
End Function

End Class

No comments:

Post a Comment