© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
10 replies
Jack

A (hopefully) basic question about singleton instances

Hello,

I don't know why but I am mixing things up in my head today with the singleton pattern. So the basic pattern goes something like this (simplified for brevity):

public Singleton
{
  private static Singleton _instance;

  public static Instance
  {
    if(_instance == null) _instance = new Singleton();
    return _instance;
  }
}
public Singleton
{
  private static Singleton _instance;

  public static Instance
  {
    if(_instance == null) _instance = new Singleton();
    return _instance;
  }
}


Now, in my head I had it that the private
_instance
_instance
variable should be an instance variable, i.e. not static. But all examples of the singleton pattern that I have found have the private instance being static. So why is this? Is there a problem with it being an instance variable? Is this just to absolutely ensure that there can only be one instance? I don't have any problem with using a private static field but it was in my head that it shouldn't be so I'd like to understand why I thought that and why it is wrong to do so.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ a question about basic C-sharp tutorials
C#CC# / help
4y ago
Question about how methods of object instances are stored
C#CC# / help
5w ago
Basic C# question
C#CC# / help
5mo ago
✅ Basic SQL question;
C#CC# / help
3y ago