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
13579 3579 579 79 9 How to the logic in code. pls give me Ans.

What are types of compatibility in VB6 There are three possible project compatibility settings: No Compatibility Project Compatibility Binary Compatibility

We have a web based program completed with .NET C# and Microsoft SQL Server. There are some reports requires to be created. Required Skills. - High Proficiency in .NET C#

What are satellite assemblies? We use resource files to store data according to the localized languages. But when you actually go for the deployment you will not like to also i

Explain Component diagrams Package: - The Package logically make group of element of a UML model. Component: - It is the actual physical module or implementation of

What precautions we need to take while deploying satellite assemblies? When we distribute the assembly, the folder structure has to be very organized. The table below shows how

I need Online Slot Video Game For A Facebook Project Description: Prepare an online slot video game for a Face book promotion in order to attract new visits and Increase the

Our company is seeking a talented PHP Developer to join our young and dynamic online media agency. Must have: - Knowledge in SQL and Databases, proven indexing and coding exp

Question: (a) Using the help of a diagram, describe the layer of the .NET framework that sits between Visual Basic.NET 2005 and the operating system. (b) Explain the charac

Explain the DataAdapter.Update() and DataSetAcceptChanges() methods. The DataAdapter.Update() method calls any of the DML statements, like UPDATE, INSERT, or DELETE statements,