Sahil Sharma
How can we pass parameters to Static Constructors?
By Sahil Sharma in C# on Oct 17 2014
  • Vikram Agrawal
    Dec, 2014 8

    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.

    • 4
  • Ajeet Mishra
    Sep, 2015 3

    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?

    • 1
  • Debendra Dash
    Apr, 2015 19

    Static constructor never have parameter.

    • 1
  • Pramod Verma
    Feb, 2015 10

    Static Constructors should not have any parameters.

    • 1
  • Anil Kumar Murmu
    Jan, 2016 15

    static constructor does not contain parameters.

    • 0
  • vipin kv
    Oct, 2015 6

    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

    • 0
  • Srinivas Pabballa
    Aug, 2015 13

    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

    • 0
  • Rahul Prajapat
    May, 2015 31

    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

    • 0
  • Kml Surani
    May, 2015 12

    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.

    • 0
  • Kml Surani
    May, 2015 12

    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.

    • 0
  • Sakthikumar Thanavel
    May, 2015 6

    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.

    • 0
  • Kml Surani
    Apr, 2015 15

    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.

    • 0
  • Pankaj  Kumar Choudhary
    Mar, 2015 23

    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.

    • 0
  • Vikram Agrawal
    Dec, 2014 8

    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.

    • 0
  • Manish Kumar Choudhary
    Nov, 2014 18

    A static constructor is called automatically to initialize the class before the first instance is created, so we can't send it any parameters.

    • 0
  • Jaganathan Bantheswaran
    Nov, 2014 1

    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.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS