static void Main(string[] args) { object sampleA = SampleA.Create(); object sampleB = SampleA.Create(); Console.WriteLine("Oluşturulan sampleA nesnesinin hash kodu: " + sampleA.GetHashCode()); Console.WriteLine("Oluşturulan sampleB nesnesinin hash kodu: " + sampleB.GetHashCode()); }
} // pattern gereği kurucu fonksiyon boş bırakılır public static SampleA Create() { lock (_lock) { if (_sampleA == null) // kontrol bloğunda tek satırlık işlemler için parantez kullanılması gerekmiyor. { _sampleA = new SampleA(); } return(_sampleA); } }