Private and static constructors are not same in execution. If you have static constructor, private constructor and public constructor, then among all first of all static constructor will execute. Try to create all three kind of constructor and debug then you will come to know execution sequence of all constructor.
They are not same in execution:A static constructor is called before the first instance is created. So its kind of global initializer. Whereas Private constructor is called after the instance of the class is created. Inheritance-wise both are same.There is difference between the two.Static constructor will be called first time when the class is referenced. A static constructor is used to initialize static members of the class. In the non static class the private or public constructor will not be called. Static members will not be initialized either by the private or public constructor. This concept can be understood by the following example.using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace OOPConcepts {class Program{static void Main(string[] args){OnlyOne.SetMyName("I m the only one."); //static constructor will be called first time when the class will be referenced.Console.WriteLine(OnlyOne.GetMyName());NoInstance.SetMyName("I have private constructor"); //No constructor will be called when the class will be referenced.Console.WriteLine(NoInstance.GetMyName());Console.Read();}}static class OnlyOne{static string name;/// /// This will be called first time when even the class will be referenced./// static OnlyOne(){name = string.Empty;Console.WriteLine("Static constructor is called");}public static string GetMyName(){return name;}public static void SetMyName(string newName){name = newName;}}public class NoInstance{static string name;private NoInstance(){name = string.Empty;Console.WriteLine("No instance private constructor is called");}public static string GetMyName(){return name;}public static void SetMyName(string newName){name = newName;}} }
Yes, i have got cleared .Thank you all