What you need to know about Static class

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 =)

Popular posts from this blog

Example to disable save as certain file type in SSRS Report Viewer

How to create DataGrid or GridView in JSP - Servlet

Control Webpart Visible/Enable using macro in Kentico