How to instantiate an object with a private constructor in C#?

You can use one of the overloads of Activator.CreateInstance to do this: Activator.CreateInstance(Type type, bool nonPublic) Use true for the nonPublic argument. Because true matches a public or non-public default constructor; and false matches only a public default constructor. For example: class Program { public static void Main(string[] args) { Type type=typeof(Foo); Foo f=(Foo)Activator.CreateInstance(type,true); } … Read more

private constructor [duplicate]

Private constructor means a user cannot directly instantiate a class. Instead, you can create objects using something like the Named Constructor Idiom, where you have static class functions that can create and return instances of a class. The Named Constructor Idiom is for more intuitive usage of a class. The example provided at the C++ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)