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

Why do we use the xmlhttprequest object in ajax, Why do we use the XMLHttpR...

Why do we use the XMLHttpRequest object in AJAX? The XMLHttpRequest object is used by JavaScript to transfer XML and other text data among client and server. The XMLHttpRequest

Readerwriter locks, What is ReaderWriter Locks? You may want to lock th...

What is ReaderWriter Locks? You may want to lock the resource only whenever data is being written and permit multiple clients to parallel read data when data is not being updat

Need experienced dot net and php programmers, Need Experienced dot Net and ...

Need Experienced dot Net and PHP Programmers Project Description: Need Experienced dot Net., JSP, PHP, Java Programmers Skilled professional and command in Programming eit

What is a gateway, What is a gateway or Router? A node that is linked t...

What is a gateway or Router? A node that is linked to two or more networks is commonly called as router or Gateway. It generally forwards message from single network to another

Learning management system, I am looking for learning management software (...

I am looking for learning management software (LMS) preferably in ASP.NET and Microsoft SQL/ MYSQL server as the database. The broad scope of the system could be 1. User managem

What is common language runtime, What is "Common Language Runtime" (CLR)?  ...

What is "Common Language Runtime" (CLR)?  CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that changes a MSIL code into the host machine language code,

Define the tooltip control, Define the ToolTip control. How can you associa...

Define the ToolTip control. How can you associate it with other controls? The ToolTip control produces a small pop-up window with explanatory text for an element it is displaye

Bug prediction and correction, Bug Prediction and Correction Project Des...

Bug Prediction and Correction Project Description: The project is about the prediction of bugs and fixes the bug in the sample program using costriage algorithm. All the requ

What benefits have web services over component object model, What advantage...

What advantages have Web services over Component Object Model (COM) and Distributed Component Object Model (DCOM)? The benefits of Web services over COM and DCOM are as follow

Microsoft application blocks, Have you ever worked with Microsoft Applicati...

Have you ever worked with Microsoft Application Blocks, if yes then which? The Application Blocks are C# & the VB.NET classes distributed as the Visual Studio projects which ca

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