Advertisement
illiden

PatternSingleton

Apr 15th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Singletone
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine(Singleton.GetInstance().SecretPassword);
  10.             Console.WriteLine(Singleton.GetInstance().SecretPassword);
  11.             Console.ReadKey();
  12.         }
  13.     }
  14.  
  15.     public class Singleton
  16.     {
  17.         private static Singleton Instance = new Singleton();
  18.         private Random _random = new Random();
  19.         public int SecretPassword { get; private set; }
  20.  
  21.         private Singleton()
  22.         {
  23.             SecretPassword = _random.Next(10000, 100000);
  24.         }
  25.  
  26.         public static Singleton GetInstance()
  27.         {
  28.             return Instance;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement