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 7887037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:28:35+00:00 2026-06-03T05:28:35+00:00

Looking around the web, I’ve seen this simple pattern that implements a (thread-safe) singleton

  • 0

Looking around the web, I’ve seen this simple pattern that implements a (thread-safe) singleton (in C#).

public sealed class MySingleton
{
    private static readonly MySingleton _instance = new MySingleton();

    private string[] _data = new string[10];

    // Private constructor, so no outsiders have access.
    private MySingleton()
    {
        // Initialize _data member here
    }

    // Static method to provide access to instance
    public static MySingleton Instance
    {
      get { return _instance; }
    }

    public string GetStringCount
    {
        return _data.Length;
    }

}

I understand that the _instance member needs to be declared as static because it is accessed from the static Instance() method.

But should other members be declared as static? By definition the singleton exists only once so the members can also only exist once (for the single instance), just as static variables exist only once.

Should I declare _data as static?

  • Will there be any functional difference?
  • Any performance difference?
  • Any other reason to prefer static or non-static?
  • 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-03T05:28:36+00:00Added an answer on June 3, 2026 at 5:28 am

    If you have a Singleton you have one instance of a class. The class members must not be static (except for the Instance property backing field). If you have more than one statics in your Singleton you have actually created not one Singleton but many Singletons. A general advice is to use the static keyword only when absolutely necessary.

    It is cleaner to store your singelton data inside your singleton instance as non static class members.

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

Sidebar

Related Questions

I have been looking around the web for this but cannot really find a
Looking around, I can't name a single web application (not web service) that uses
So I have been wandering around the web for some time looking for this
I've been looking around for a good web automator (something that can simulate a
I've been looking around the web and all the examples I've seen have a
I'm asking this question here because after looking around the web for answers, I
Looking around on the Web I found that the Ruby Time class has Time#advance
I've been looking around the internet hoping that this is possible, I basically need
I have been looking around on the web and found some articles about the
If been looking around the web and can't seem to find any good solutions

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.