CrazyEngineers
  • How the static constructor is used in object creation?

    patil.ashu01

    patil.ashu01

    @patilashu01-wqV4iY
    Updated: Oct 21, 2024
    Views: 1.1K
    Hey friends, I am stuck here understanding static constructors. Have gone through many posts and online articles. But I am unclear yet. It says static constructor is called automatically before the first instance is created. But instance is created using default constructor, then how the static constructor is used in object creation? I know I am making a weird mistake but confused. Please help.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberJan 9, 2013

    would you please specify which language you are talking about?
    As per Java, if you declare a constructor as static it will not longer be "a" constructor.
    Are you sure? This action cannot be undone.
    Cancel
  • patil.ashu01

    MemberJan 9, 2013

    Working in C#
    ianoop
    would you please specify which language you are talking about?
    As per Java, if you declare a constructor as static it will not longer be "a" constructor.
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberJan 10, 2013

    patil.ashu01
    Hey friends, I am stuck here understanding static constructors. Have gone through many posts and online articles. But I am unclear yet. It says static constructor is called automatically before the first instance is created. But instance is created using default constructor, then how the static constructor is used in object creation? I know I am making a weird mistake but confused. Please help.
    😀 I am going to tell the basic concept of static constructor which will clear its usage :
    Static constructor is used to initialize the static variables.
    Now if we initialize the static variables using the normal (ie non static) constructor, its value will be re-setted every time a new object is created.
    And regarding ur question, if we have not created static constructor, then only default constructor will be used. I hope ur doubt is cleared 👍.
    Are you sure? This action cannot be undone.
    Cancel
  • patil.ashu01

    MemberJan 10, 2013

    rahul69
    😀 I am going to tell the basic concept of static constructor which will clear its usage :
    Static constructor is used to initialize the static variables.
    Now if we initialize the static variables using the normal (ie non static) constructor, its value will be re-setted every time a new object is created.
    And regarding ur question, if we have not created static constructor, then only default constructor will be used. I hope ur doubt is cleared 👍.
    Thank You...
    Are you sure? This action cannot be undone.
    Cancel
  • rahul69

    MemberJan 10, 2013

    patil.ashu01
    Thank You...
    you're welcome...
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register