单例模式
来源:互联网 发布:波司登羽绒服 知乎 编辑:程序博客网 时间:2024/05/24 01:01
using UnityEngine;
using System.Collections.Generic;
public class QSingleton<T> where T :class, new ()
{
public static T _instance;
// public static readonly object syslock = new object();
public QSingleton()
{
}
public static T getInstance()
{
//if (_instance == null)
//{
//lock (syslock)
//{
if (_instance == null)
{
_instance = new T();
}
//}
// }
return _instance;
}
using System.Collections.Generic;
public class QSingleton<T> where T :class, new ()
{
public static T _instance;
// public static readonly object syslock = new object();
public QSingleton()
{
}
public static T getInstance()
{
//if (_instance == null)
//{
//lock (syslock)
//{
if (_instance == null)
{
_instance = new T();
}
//}
// }
return _instance;
}
}
using UnityEngine;
using System.Collections.Generic;
public class SingClass : QSingleton<SingClass>
{
public int a = 1;
// Use this for initialization
public void St () {
Debug.Log(12);
Debug.Log(a);
}
}
using UnityEngine;
using System.Collections;
public class Script : MonoBehaviour {
void Start () {
SingClass.getInstance().St();
// Debug.Log(SingClass._instance.a);
}
}
单列模式http://cantellow.iteye.com/blog/838473
阅读全文
0 0
- 单例、单例模式
- 单例模式-多线程单例模式
- 单件模式(单例模式)
- 设计模式------单例模式
- 设计模式------单例模式
- 设计模式-单例模式
- 设计模式 - 单例模式
- 设计模式---单例模式
- 设计模式---单例模式
- PHP模式-单例模式
- 【设计模式】单例模式
- 设计模式-单例模式
- 设计模式----单例模式
- 设计模式--单例模式
- 设计模式-单例模式
- 单例模式(单子模式)
- 设计模式-单例模式
- [设计模式] 单例模式
- Unable to get the default Bean Validation factory
- 动画[2]TweenAnimation 使用场景
- Matlab学习笔记(3)——diag函数的使用
- Linux下C语言的多线程编程
- (1)Java的四大特性
- 单例模式
- jquery miniui的体验
- Redis使用认证密码登录
- 业余草:《名博是怎样炼成的》经典语句整理
- PHP 经典有趣的算法收集
- sphinx多索引的同时调用
- [bzoj3306]树 dfs序+线段树
- cache是什么文件?
- Executor框架和线程池