单例设计的几种写法

2017-04-03  本文已影响0人  我的_一个道姑朋友

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 泛型

{

class Program

{

static void Main(string[] args)

{

aaa.a();

}

}

public class aaa

{

public static void a()

{

Brid brid = Brid.brid();

Console.WriteLine(brid.i);

int a=plane.Instance.j;

Console.WriteLine(a);

//int b = BT.bt.a;

//Console.WriteLine(b);

int c=  TapEvent.inst.c;

Console.WriteLine(c);

Console.ReadKey();

}

}

class plane//单例

{

public int j = 20;

private static plane mInstance;

public static plane Instance

{

get

{

if (null == mInstance) mInstance = new plane();

return mInstance;

}

}

public void StartGame()

{

Console.WriteLine("plane单例被调用了!");

}

}

public  class Brid//单例

{

public int i = 10;

private static Brid mBrid = null;

public static Brid brid()

{

if (mBrid == null) mBrid = new Brid();

return mBrid;

}

public void StartGame()

{

Console.WriteLine("brid单例被调用了!");

Console.ReadKey();

}

}

class BT//单例

{

public int a = 30;

private static BT mbt;

public static BT bt

{

get { return mbt; }

set { mbt = value; }

}

void start()

{

mbt = this;

}

}

class TapEvent//单例

{

public int c = 40;

private static TapEvent _Inst;

public static TapEvent inst { get { return _Inst; } }

}

}

上一篇 下一篇

猜你喜欢

热点阅读