| 1234567891011121314151617181920212223242526272829 |
- using System;
- namespace GFGGame
- {
- public class SingletonBase<T> where T: class,new()
- {
- private static T _instance;
- private static readonly object _lock = new object();
- public static T Instance
- {
- get
- {
- if (_instance == null)
- {
- lock (_lock)
- {
- if (_instance == null)
- {
- _instance = (T)Activator.CreateInstance(typeof(T), true);
- }
- }
- }
- return _instance;
- }
- }
- }
- }
|