Interviews16 answers
How can we pass parameters to Static Constructors?
16 Answers
static constructor does not contain parameters.
Anil Kumar MurmuPosted Jan 15, 2016, 1:02 AM EST
We cannot pass parameters to Static constructor
Reason: We cannot invoke Static constructor from the code, it will invoked automatically and only once, either on creation of first instance of the class or on accessing static member of the class
vipin kvPosted Oct 6, 2015, 3:17 AM EDT
As MSDN says, A static constructor is called automatically to initialize the class before the first instance is created. Therefore you can't send it any parameters.
If the CLR must call a static constructor how will it know which parameters to pass it?
Ajeet MishraPosted Sep 3, 2015, 5:21 AM EDT
your question is wrong...
static constructor is a parameterless constructor.
It will contain any parameters.
bcz static constructor will invoke at the time of class is loading and you can't pass any parameters.
static constructor is a parameterless constructor
it should not have any access modifier
Srinivas PabballaPosted Aug 13, 2015, 12:50 AM EDT
We can only pass parameter to a non static constructor(parametrized constructor )
but we can not pass any parameter to a static constructor...
Because access modifier(Public,Protected) is not allowed for static constructor
Rahul PrajapatPosted May 31, 2015, 7:35 PM EDT
static constructor is called when the execution of the class is started. It is the first member to be execute in the class. at this time how can we pass any parameters to it. if we create object of the class then it will call the non static constructor. so we can not pass any parameters into it at any cost.
Posted May 12, 2015, 1:34 AM EDT
static constructor is called when the execution of the class is started. It is the first member to be execute in the class. at this time how can we pass any parameters to it. if we create object of the class then it will call the non static constructor. so we can not pass any parameters into it at any cost.
Posted May 12, 2015, 1:34 AM EDT
Static constructor does not have access specifier and parameter. It called automatically when we try to access the class at first time. it will helpful to initialize the value the static field of the class.
Note:
The non static class also capable to have the static constructor. but static constructor only has the rights to access the static fields the that class.
Sakthikumar ThanavelPosted May 6, 2015, 10:06 AM EDT
Static constructor never have parameter.
Debendra DashPosted Apr 18, 2015, 9:38 PM EDT
As MSDN says A static constructor is called automatically to initialize the class before the first instance is created, therefore you can't send it any parameters.
Posted Apr 15, 2015, 7:20 PM EDT
We can only pass parameter to a non static constructor(parametrized constructor )
but we can not pass any parameter to a static constructor...
Because access modifier(Public,Protected) is not allowed for static constructor.
Pankaj Kumar ChoudharyPosted Mar 23, 2015, 7:42 PM EDT
Static Constructors should not have any parameters.
Pramod VermaPosted Feb 10, 2015, 8:08 AM EST
static constructor is called when the execution of the class is started. It is the first member to be execute in the class. at this time how can we pass any parameters to it. if we create object of the class then it will call the non static constructor. so we can not pass any parameters into it at any cost.
Vikram AgrawalPosted Dec 8, 2014, 2:01 AM EST
static constructor is called when the execution of the class is started. It is the first member to be execute in the class. at this time how can we pass any parameters to it. if we create object of the class then it will call the non static constructor. so we can not pass any parameters into it at any cost.
Vikram AgrawalPosted Dec 8, 2014, 2:00 AM EST
A static constructor is called automatically to initialize the class before the first instance is created, so we can't send it any parameters.
Manish Kumar ChoudharyPosted Nov 17, 2014, 8:12 PM EST
You cant pass parameters to Static Constructors, because you cannot access any non-static member outside of a static method (constructor too).
class Cons
{
public static string name = "Jagan";
public string age;
static Cons ()
{
// you can access only static members [name] but NOT non-static [age]
}
}
If your intention of passing parameter to Static Constructor is to set value of a Static variable, then you can directly set using class name. So thats why Static Constructor does not need arguments.
Jaganathan BantheswaranPosted Nov 1, 2014, 12:44 AM EDT











