Static Class 

* Only 1 instance of the object is created for static classes
* Static class Should be declare static keyword for declare constructor or method or variable
* Can't specify access specifier for static Constructor
* Static constructor should run only once.

Example

        public static class MyClass
        {
            static MyClass()
            {
                Console.WriteLine("Static Constructor");
            }
            public static void SomeMethod()
            {
                Console.WriteLine("Some Methods");
            }

        }

 static void Main(string[] args)
        {

            MyClass.SomeMethod();
            MyClass.SomeMethod();
   }

O/P
Static Constructor
Some Methods
Some Methods


Comments

Post a Comment

Popular posts from this blog

Sites.Selected | Graph API SharePoint Permission

Configure the SharePoint Online App Catalog

Azure Function | Sharepoint List item | Call from Power Automate Flow