crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

What is static modifier and its example
Question Posted on 23 Aug 2011Home >> DotNet >> C# >> What is static modifier and its example

AS the name suggest static Static modifier are used to declare a static member and belongs to type itself rather than to specific object. We can use static modifier with fields, operators, properties, events, constructors and methods but we cannot used with indexers, destructors, or types.Once we declare static varible it will automatically initialized in memory by there default value or value defined by user once we will initialized static variable it will never reinitialized in memory on other hand local variables local variable reinitialized in memory every time they call as well as all the objects of the class share the same address of static variable.
In C# the static keyword indicates a class variable. In VB the equivalent keyword is Shared. Its scoped to the class in which it occurs.
Below is the example to understand what static is and where to use static
class TestStatic
{
 static int a = b;
 static int b = 1;
 static void Main()
 {
  Console.WriteLine(TestStatic.a);
  Console.WriteLine(TestStatic.b);
  TestStatic.a = 2;
  Console.WriteLine(TestStatic.a);
 }
}

-----Output-------
0 ///by default it will take 0 value of a
1
2
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Simplest definition of partial classes and its rules?

Definition of Tuple class with some examples?

Define Race Condition in cSharp?

C#.Net Reserve Words

can we inherit private class level variables in c#






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap