コード例 #1
0
        static async Task Main(string[] args)
        {
            Adam adam        = Adam.GetInstance();
            Adam anotherAdam = Adam.GetInstance();

            Console.WriteLine(adam is Adam);
            Console.WriteLine(ReferenceEquals(adam, anotherAdam));

            Console.ReadKey();
        }
コード例 #2
0
 public static Eve GetInstance(Adam adam)
 {
     if (adam is null)
     {
         throw new ArgumentNullException("Eve is created from the rib of Adam");
     }
     else
     {
         return(_eve ?? (_eve = new Eve()));
     }
 }
コード例 #3
0
 public static Adam GetInstance() => _adam ?? (_adam = new Adam());