Skip to content

Instantly share code, notes, and snippets.

@qiuyuzhou
Created September 14, 2013 15:13
Show Gist options
  • Save qiuyuzhou/6562807 to your computer and use it in GitHub Desktop.
Save qiuyuzhou/6562807 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LevelEditor
{
public sealed class Singleton<T> where T: new()
{
private static volatile T instance;
private static object syncRoot = new Object();
private Singleton() { }
public static T Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new T();
}
}
return instance;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment