Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
AJAX
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
general knowledge
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 


What is static modifier and its example
Question Posted on 23 Aug 2011

Home >> 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



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


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#






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |