Shared (vb.net)/static(c#) variables, DOT NET Programming

What are shared (VB.NET)/Static(C#) variables?

Shared/Static classes are used when a class gives functionality which is not specific to any instance. In brief if you want an object to be shared between multiple instances you will use a Shared/Static  class.

The key features of Static/Shared classes are as follows:-

1) They can't be instantiated. By default the object is created on the first method call to that object.

2) The Shared/Static classes can not be inherited.

3) The Shared/Static classes can have only static members.

4) The Shared/Static 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

961_shared in action.png

Figure :-Shared/Static In Action

Posted Date: 9/22/2012 3:14:50 AM | Location : United States







Related Discussions:- Shared (vb.net)/static(c#) variables, Assignment Help, Ask Question on Shared (vb.net)/static(c#) variables, Get Answer, Expert's Help, Shared (vb.net)/static(c#) variables Discussions

Write discussion on Shared (vb.net)/static(c#) variables
Your posts are moderated
Related Questions
EMR ONC MU2 CERTIFICATION Project Description: We are looking for someone with experience in EMR MU2 certification per ONC needs. If you have experience and participate in

Produce a server setup where I have access to ip address Project Description: I would require using ftp or remote desktop to put software on your server (must be a united sta

What' is the sequence in which ASP.NET events are processed? The sequence in which the ASP.NET events occur are as folows :- 1.     Page_Init. 2.     Page_Load. 3.

What is the difference between Stored Procedure (SP) and User Defined Function (UDF)? Some of major differences between a stored procedure and user defined are as follows:-

I need a Web Application UI Modernization - Preliminary Technology Assessment We are seeking to overhaul a 10-year old enterprise application, CRM-related as well as web-based t

Design an interface and add code to command buttons using case statement, to find coursework to be calculated using formula 0.6*1/6*total Mark

Differences between Datagrid, Datalist and Repeater?   1. Datagrid has paging whereas Datalist doesnt. 2. Datalist has a property called repeat. Direction = vertical/horizon

Install Modules to enhance Site Proformance Project Description: As shown, I need the subsequent modules installed, to improve loading time for my graphics and images, improv


What are design patterns? The Design patterns are recurring solution to the recurring problems in the software architecture. There are 3 basic classification of patterns Behavi