单例设计的几种写法

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; } }

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,390评论 19 139
  • C#(C-Sharp)是Microsoft的新编程语言,被誉为“C/C++家族中第一种面向组件的语言”。然而,不管...
    浮生岁月阅读 9,170评论 0 7
  • 1. [C#语言基础]请简述拆箱和装箱。 答: 装箱操作: 值类型隐式转换为object类型或由此值类型实现的任何...
    胤醚貔貅阅读 10,314评论 1 29
  • 目录本次给大家介绍的是我收集以及自己个人保存一些.NET面试题第二篇简介1.接口2.您在什么情况下会用到虚方法或抽...
    寒剑飘零阅读 5,971评论 0 10
  • 如是而坐,如是而听,如是而思,如是而梦。风来风往,雨声相和,好一滂沱大雨!好一首悲壮凯歌!! 雾都之雨滔滔,震撼,...
    说鱼之乐阅读 1,248评论 0 2