本文主要是介绍设计模式->单例模式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public class RedisManagerSingleton
{
private static RedisManagerSingleton _redisManagerSingleton;
private static readonly object _lock = new object();
private RedisManagerSingleton()
{
}
public static RedisManagerSingleton GetSingleton()
{
if (_redisManagerSingleton == null)
{
lock (_lock)
{
if (_redisManagerSingleton == null)
{
_redisManagerSingleton = new RedisManagerSingleton();
}
}
}
return _redisManagerSingleton;
}
}
这篇关于设计模式->单例模式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!