C# program for Static Constructor



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication7
{
    class Sconstructor
    {

        public Sconstructor()
        {

            Console.WriteLine("Instance  Constructor");
        }

        static Sconstructor()
        {
            Console.WriteLine("Static  Constructor");
        }
    }
    class StaticConstructor
    {
        static void Main()
        {
            //Static Constructor and instance constructor, both are invoked for first instance.
            Sconstructor T1 = new Sconstructor();

            //Only instance constructor is invoked.
            Sconstructor T2 = new Sconstructor();


            Console.Read();
        }
    }
}

Output :


Previous Post Next Post