Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Singleton "GetInstance" Method or "Instance" Property?

From the perspective of an API end-user who needs to "get an the instance" of a Singleton class, do you prefer to "get" an the .Instance property or "call" a .GetInstance() Method?

public class Bar
{
    private Bar() { }

    // Do you prefer a Property?
    public static Bar Instance
    {
        get
        {
            return new Bar();
        }
    }

    // or, a Method?
    public static Bar GetInstance()
    {
        return new Bar();
    }
}
like image 451
jlang Avatar asked Sep 01 '09 04:09

jlang


1 Answers

In C#, I would far prefer .Instance, as it fits in with the general guidelines.

like image 115
Noon Silk Avatar answered Oct 14 '22 09:10

Noon Silk