Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   how to call a private constructor (http://www.go4expert.com/forums/private-constructor-t6280/)

cmrhema 10Sep2007 20:41

how to call a private constructor
 
Hello
I have created a class also a constructor which is (should be, its one of the conditions) private.
Now I am supposed to call it in the main program. My team leader says there is a trick to call it. I can call the variable j(as it is static). but not con.
Please help me out.

public class con
{
private con()
{
Console.WriteLine("private constructor");
}
public static int j = 5;
}
}

Thanking you
cmrhema

DaWei 11Sep2007 02:13

Re: how to call a private constructor
 
Overload operator new in your class, and make it public.

cmrhema 11Sep2007 09:01

Re: how to call a private constructor
 
Thanks for the reply

I am not supposed to make the constructor public(One of the conditions).
Moreover I am required to write a method inside the constructor that can be public and i am supposed to call it in the main()


All times are GMT +5.5. The time now is 10:34.