Пример #1
0
    public static SingletonSimple getInstance()
    {
        if (instance == null)
        {
            instance = new SingletonSimple();
        }

        return(instance);
    }
Пример #2
0
        public static void SingletonSimpleExample()
        {
            SingletonSimple db  = SingletonSimple.Instance;
            SingletonSimple db2 = SingletonSimple.Instance;

            Console.WriteLine("Population of Kyiv equals: " + db.GetPopulation("Kyiv"));
            Console.WriteLine("Population of London equals: " + db2.GetPopulation("London"));

            var test1 = "test1";
            var test2 = "test2";

            Console.WriteLine("\n########Compare hash codes#########\n");

            Console.WriteLine("Is db hash code equal to db2 hashcode?: "
                              + (db.GetHashCode() == db2.GetHashCode()));
            Console.WriteLine("Is test1 hash code equal to test2 hashcode?: "
                              + (test1.GetHashCode() == test2.GetHashCode()));
        }