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

Assignment Help:

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


Related Discussions:- Shared (vb.net)/static(c#) variables

Mailer - mail sender, mailer - mail sender Project Description: I wan...

mailer - mail sender Project Description: I want a mailer: -run on Windows Server 2008 -use how many theard i need -more details speak on private Skills required

Unity 4 ios pro developer to prepare link.xml, Unity 4 iOS Pro Developer to...

Unity 4 iOS Pro Developer to prepare link.xml Project Description: I'm seeking an iOS developer with a Unity 4 iOS Pro license to prepare a link.xml file that will let my pro

What are the components of wf 4.0, What are the components of WF 4.0? W...

What are the components of WF 4.0? WF having of various components that work together to make desired workflow. The components of WF are given as follows: Workflows and a

Required c# programmer, The program is broke now but explains in text and p...

The program is broke now but explains in text and printscreens the specific things i have to do to implement new bookies new sports and change settings for looking for arbs on two

How to avoid deadlock in threading?, Avoid deadlock in threading The be...

Avoid deadlock in threading The best  and careful planning may avoid deadlocks.There are so many ways Microsoft has provided by which you can decrease deadlocks for example Int

Use of attribute, What is the use of attribute  ? This attribute wo...

What is the use of attribute  ? This attribute works as a compatibility option. We know that ASP worked in STA model and ASP.NET works in MTA model, but what if your ASP.NET

What is the difference between oledb provider and sqlclient, What is the di...

What is the difference between OLEDB Provider and SqlClient? With respect to usage, there is no difference among OLEDB Provider and SqlClient. The dissimilarity lies in their p

Fill factor, What is fill factor? The 'fill factor' option describes ho...

What is fill factor? The 'fill factor' option describes how full SQL Server will make each index page. When there is no free space to insert a new row on the index page, the SQ

I want text or image printing counter, I want Text/Image printing Counter ...

I want Text/Image printing Counter Project Description: Need your help in our C# programming project. We need to pass this project in two weeks starting from now to pass our

Information retrieval from multi-agent system, Information Retrieval from M...

Information Retrieval from Multi-Agent System with Data Mining in Cloud Computing Project Description: I have planned one research model on "Information Retrieval through Mul

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd