Можно ли использовать конструктор при использовании синглтона для инициализации поля? и как это сделать? или инициализировать придется с помощью свойств?
Пример с сайта:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Одиночка
{
class Program
{
static void Main(string[] args)
{
Earth earth1 = Earth.Instance();
Earth earth2 = Earth.Instance();
if (earth1 == earth2)
Console.WriteLine("одинаковы");
else
Console.WriteLine("не одинаковы");
Console.Read();
}
}
class Earth
{
int chislo;
private static Earth instance = new Earth();
protected Earth()
{
}
public static Earth Instance()
{
return instance;
}
}
}