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, 6929👍, 0💬
How Are Vertical Margins between Two Block Elements Collapsed? - CSS Tutorials - Understanding Multi...
What Is a TD Tag/Element? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells A "td" elemen...
The object that contains all the properties and methods for every ASP.NET page, that is built is .. ...
Explain simple Walk through of XmlReader ? In this section we will do a simple walkthrough of how to...
Regarding C Coding Given: Line in file Contents 30 int * someIDs, theFirst, *r; 110 someIDs =GetSome...