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
I need mt4 programmer Project Description: I'm seeking a professional programmer to teach me MQL I have few years experience in manual trading but totally NONE in MT4 / EA

Project Description: Online game development 1. Online Live Baccarat Game is required - server program(IOCP or ect..). - 2D graphic design. - client program. - we

What is cloud computing? The cloud computing is the computing which is completely based on the Internet. It can also be explained as the next stage in the evolution of the Inte


I need Academic expert for Genetic Algorithm Project Description: Seeking academic expert for Genetic Algorithm. Please bid on this project if you will start work today. S

How can you raise custom errors from stored procedure? The RAISERROR statements areĀ  used to produce an ad hoc error message or to retrieve acustom message which is stored in t

ASP Programmer I need a fixing all W3c validation errors and it is a ASP website. Have any queries please send a message and I will provide more information on project. De

I need Web Based Inventory Management System Project Description: I require a build in software which has the subsequent features, if anybody has ready to use web based appli

Is spending in projects constant throughout the project? Generally in initial stage of projects (design and requirement phase) the cost is very less (as you require maximum bus

I need Ninjatrader Strategy Project Description: UI for managing orders, entering trades. This project will probably take several months and I need dedicated resources. Sk