单例模式实例
public class AudioManager  {

    private static AudioManager _instance;

    private AudioManager() { }

    public static AudioManager Instance {
        get {
            if (_instance == null) {
                _instance = new AudioManager();
            }
            return _instance;
        }
    }
}

使用一个私有变量来保存唯一的实例,设置构造方法为私有的,不让外部有实例化的可能。

通过一个公开的属性来获取这个唯一的实例。


首页 我的博客
粤ICP备17103704号