Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Task #888250 » Program.cs

Евгений Миненко, 2020-09-21 10:07 AM

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Obj2
{
//ОДИНОЧКА
class Singleton
{
private static Singleton test1 = null; // не содержит сыллки на объект
//private static string test2;

protected Singleton() { } // что бы не присваивалось

public static Singleton Metod()
{

if (test1 == null) // содержит ли она ссылку на объект

test1 = new Singleton();// если не содержит, присваиваем новую ссылку

return test1;//если содержит , то сразу возрощаем

}

}
class Program
{
static void Main(string[] args)
{

Singleton obj1 = Singleton.Metod();
Console.WriteLine(obj1.GetHashCode());
Singleton obj2 = Singleton.Metod();
Console.WriteLine(obj2.GetHashCode());
Console.ReadLine();
}
}
}

(2-2/2)