What are shared (VB.NET)/Static(C#) variables
What are shared (VB.NET)/Static(C#) variables?
Static/Shared classes are used when a class provides functionality which is not specific to
any instance. In short if you want an object to be shared between multiple instances you
will use a static/Shared class.
Following are features of Static/Shared classes :-
ć They can not be instantiated. By default a object is created on the first method call to that object.
ć Static/Shared classes can not be inherited.
ć Static/Shared classes can have only static members.
ć Static/Shared classes can have only static constructor.
Public Class ClsShared Shared intCount As Integer Public Function AddCount() As Integer intCount = intCount + 1 Return intCount End Function End Class Public Class FrmSharedClasses Inherits System.Windows.Forms.Form Private Sub CmdInstance1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdInstance1.Click Dim pobjClsShared As New ClsShared() MessageBox.Show(The count at this moment is & pobjClsShared.AddCount.ToString()) End Sub Private Sub CmdInstance2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdInstance2.Click Dim pobjClsShared As New ClsShared() MessageBox.Show(The count at this moment is & pobjClsShared.AddCount.ToString()) End Sub End Class
2007-10-23, 6247👍, 0💬
How To Select an Oracle System ID (SID)? - Oracle DBA FAQ - Creating New Database Instance Manually ...
What are the different storage classes in C? C has three types of storage: automatic, static and all...
Have you ever worked with Microsoft Application Blocks, if yes then which? Application Blocks are C#...
How To Run a JUnit Test Class? A JUnit test class usually contains a number of test methods. You can...
What is AL.EXE and RESGEN.EXE? In the previous question you have seen how we can use resource files ...