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

Leasetime, What are LeaseTime, Sponsorship Time, Renew on Call Time and Lea...

What are LeaseTime, Sponsorship Time, Renew on Call Time and Lease Manager Poll Time? In the normal .NET environment objects lifetime is managed by garbage collector. But inrem

Create and populate a checkboxlist control, Question: (a) The ObjectDa...

Question: (a) The ObjectDataSource control is an alternative design approach to using AccessDataSource or SqlDataSource controls. Explain and illustrate how an ObjectDataSourc

Precautions for state server mode working, What are the precautions so that...

What are the precautions so that StateServer Mode work properly? Following are some points to remember so that StateServer Mode works properly:- a) StateServer mode session

Use of "must inherit" keyword in vb.net, What is the use of "Must Inherit" ...

What is the use of "Must Inherit" keyword in VB.NET? If you want to create an abstract class in the VB.NET it is done by using the "MustInherit" keyword.You can't create an obj

What is different overloading and overriding, What is different overloading...

What is different overloading and overriding, please explain

Explain image generator (ngen.exe), Image Generator (Ngen.exe) The Ngen...

Image Generator (Ngen.exe) The Ngen.exe (Native Image Generator) allows you to run the JIT compiler on your assembly's MSIL and generate native machine code which is cached to

I want a panel for youtube views and facbook, I want a Panel for youtube vi...

I want a Panel for youtube views and facbook likes. I need a panel made that can increase facebook fanpage likes, and that will increase youtube video views. Youtube views an

Required experienced dot net. php programmers, Required Experienced dot Net...

Required Experienced dot Net., JSP, PHP, Java Programmers Skilled professional and command in Programming either any one of the given mentioned programming coding with database

Explain the concept of exceptions in .net environment, VB. Net & XML 1....

VB. Net & XML 1. Design a form based applications using labels, text boxes, and buttons to perform basic arithmetic operations on integers. 2. Explain the concept of Excepti

Define an event, Define an event. Whenever an action takes place in a c...

Define an event. Whenever an action takes place in a class, that class gives a notification to other classes or objects that are assigned to perform certain tasks. These notifi

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