Tuesday 22 April 2014

What you need to know about Static class

Leave a Comment

Static Class Properties

  • A static class cannot be instantiated. That means you cannot create an instance of a static class using new operator. 
  • A static class is a sealed class. That means you cannot inherit any class from a static class. 
  • A static class can have static members only. Having non-static member will generate a compiler error.
  • A static class is less resource consuming and faster to compile and execute. 

Static Class Example

Public static class MyStaticClass 
{ 
    Private static int myStaticVariable; 
    Public static int StaticVariable; 
    { 
       Get 
       { 
          return myStaticVariable; 
       }  
       Set 
       {  
         myStaticVariable = value; 
       } 
   } 
    Public static void Function() 
    { 
    } 
} 

Note : The static class can directly called out from the other class for example you create class ClassA, and you can directly type in ClassA to call Function method in class MyStaticClass like this.
MyStaticClass.Function();


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.