Interviews5 answers
What is a static constructor in C#?
5 Answers
1) A class can have one and only one Static Constructor.
2) The Static Constructor should not have any access modifier.
3) Static Constructors should not have any parameters.
4) The Static constructor will be executed only one time irrespective of number of objects created
5) Runtime invokes the Static Constructor when it creates an instance of the class or before the first static member being accessed.
6) The Static Constructor executes before any of the instance level constructors.
Pramod VermaPosted Feb 10, 2015, 8:52 AM EST
constructor are only default ,parameterised and copy i didn't ever listen static constructor ... but static word can use with constructors ...
like
public sara()
{
Console.writeLine(" its non static and have an extra place in heap");
}
static public sara()
{
console.writeLine("its static,and the value place on the same place no extra space here use it ");
}
Sara MeCaalPosted Aug 30, 2014, 9:52 AM EDT
constructor are only default ,parameterised and copy i didn't ever listen static constructor ... but static word can use with constructors ...
like
public sara()
{
Console.writeLine(" its non static and have an extra place in heap");
}
static public sara()
{
console.writeLine("its static,and the value place on the same place no extra space here use it ");
}
Sara MeCaalPosted Aug 30, 2014, 9:52 AM EDT
A constructor that is declared using static modifier is a static constructor. Static constructor executes one and only one time in the life cycle of class. It is the first block of code to execute in class. A static constructor can not be parametrized.
Ranjit PowarPosted Apr 23, 2014, 9:52 AM EDT
A constructor that is declared using static modifier is a static constructor. Static constructor executes one and only one time in the life cycle of class. It is the first block of code to execute in class. A static constructor can not be parametrized.
Ranjit PowarPosted Apr 23, 2014, 9:51 AM EDT


