Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:39:36+00:00 2026-06-04T18:39:36+00:00

I have some code as shown below. I guess it is Singleton pattern. Why

  • 0

I have some code as shown below. I guess it is Singleton pattern. Why do I need a static constructor. Also what is the advantages of this? Thanks for your reply …

  public sealed class Myclass
  {
    static Myclass()
    {
        Myclass.Application = new Myclass();
    }

    protected Myclass()
    {

    }

    static Myclass _application;

    public static Myclass Application
    {
        get { return Myclass._application; }
        protected set { Myclass._application = value; }
    }

    string _name;

    public string Name
    {
        get { return _name}
        protected set { _name= value; }
    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:39:37+00:00Added an answer on June 4, 2026 at 6:39 pm

    To start with, this class is somewhat odd for having a protected constructor. It’s not a fatal flaw given that it’s sealed, but it’s distinctly odd.

    There’s a potential difference in timing between this code and the nearly-equivalent use of a static variable initializer:

    static readonly Myclass _application = new Myclass();
    

    (There’s no need for a setter in this case, of course.)

    You can’t do that with an automatically implemented property though.

    Using static initialization in some form gets you “free” thread-safety – you don’t need to do any locking in order to get lazy initialization.

    You may find my singleton implementation article interesting for more options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSF code that currently works (as shown below), and I need
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have some code like this: doDatabaseFetch { ... @synchronized(self) { ... } }
I have some code in Netbeans 6.1 editor that looks like this fooString(8) fooString(8)
I have some code where I use a thread static object in C#. [ThreadStatic]
I have a servlet coded in Scala. I have some code like this in
Simple problem: With the XML layout shown below, I have some views wrapped in
I have some javascript as shown below for (var titleKey in data.d) { var
I have written the code shown below. my problem is that I can't touch
Hi people I have the following code (shown below) and I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.