16
Reply

How can we pass parameters to Static Constructors?

Sahil Sharma

Sahil Sharma

Oct 17, 2014
15.1k
0

    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 Agrawal
    December 08, 2014
    4

    Static constructor never have parameter.

    Debendra Dash
    April 19, 2015
    1

    Static Constructors should not have any parameters.

    Pramod Verma
    February 10, 2015
    1

    static constructor does not contain parameters.

    Anil Kumar Murmu
    January 15, 2016
    0

    We cannot pass parameters to Static constructorReason: 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 kv
    October 06, 2015
    0

    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 Mishra
    September 03, 2015
    0

    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 Pabballa
    August 13, 2015
    0

    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 Prajapat
    May 31, 2015
    0

    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.

    Kml Surani
    May 12, 2015
    0

    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.

    Kml Surani
    May 12, 2015
    0

    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.

    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.

    Kml Surani
    April 15, 2015
    0

    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.

    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 Agrawal
    December 08, 2014
    0

    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 Choudhary
    November 18, 2014
    0

    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 Bantheswaran
    November 01, 2014
    0