public static SinglePerson GetInstance() { if (_instance == null) { _instance = new SinglePerson(); Console.WriteLine("创建成功" + DateTime.Now.ToString("yyyy-MM-dd:hhmmss")); } return(_instance); }
public void PropertyNameTest() { // property name does not exist Assert.IsFalse(SinglePerson.IsValidProperty("FirstName11")); // property name does exist case sensitive Assert.IsTrue(SinglePerson.IsValidProperty("FirstName")); // property name does not exists, casing Assert.IsFalse(SinglePerson.IsValidProperty("firstName")); // property name does exists, casing ignored Assert.IsTrue(SinglePerson.IsValidPropertyIgnoreCase("firstname")); }
private static void Demo(string[] args) { for (int i = 0; i < 1000; i++) { Task.Factory.StartNew(() => { SinglePerson p = SinglePerson.GetInstance(); Singleton1 p1 = Singleton1.GetInstance(); Singleton2 s2 = Singleton2.GetInstance(); }); } Console.ReadKey(); }