Interviews10 answers
10 Answers
how can trust
RATNESH SAHUPosted Feb 11, 2016, 12:46 AM EST
yes we can have static constructor inside a non-static class.
Anil Kumar MurmuPosted Jan 15, 2016, 1:19 AM EST
Yes, it can.But user will not have any control on its invoke.
AshishPosted Apr 23, 2014, 10:05 PM EDT
Yes, we can have static constructor . But user have no control over evoking it.
AshishPosted Apr 22, 2014, 4:28 AM EDT
Yes, It can have..
http://msdn.microsoft.com/en-us/library/ms173116%28v=vs.80%29.aspx
Ravikumar GPosted May 13, 2013, 8:13 PM EDT
yes it is possible,
Refer this link
http://sandeepmhatre.blogspot.com/2013/03/constructors.html
Sandeep MhatrePosted Apr 23, 2013, 5:03 AM EDT
but we can not use this value every time variable is 0
Tanuj KhuranaPosted Feb 24, 2013, 11:19 PM EST
yes we can create the static constructor in non static class...
it is parameter less and how static constructor called only once when how many number of objects created to the that class
static fields only one reference
jeevan prasadPosted Feb 12, 2013, 12:00 AM EST
Yes Normal class can have static constructor but only one.
it automatically called only once when any of class member is first time called or access.. even at instance creation.
And important thing is static constructor should be parameterless...
Dinesh BhojePosted Jan 16, 2013, 8:35 PM EST
Yes, it is possible.
But we have to create an object of the class inside the static constructor and then initialize the non static member through the object reference.
And to initialize static member of the class too.
class Class2
{
int a;
static Class2()
{
Class2 p = new Class2();
p.a = 45;
System.Console.WriteLine(p.a);
}
static void Main()
{
}
}
But we have to create an object of the class inside the static constructor and then initialize the non static member through the object reference.
And to initialize static member of the class too.
class Class2
{
int a;
static Class2()
{
Class2 p = new Class2();
p.a = 45;
System.Console.WriteLine(p.a);
}
static void Main()
{
}
}
ShambhuPosted Dec 16, 2012, 2:06 AM EST





