泛型

     现实是什么?

    不懂  ,不想懂 !!!

     那不如就这样幼稚的活着,不要醒悟,饿只是傻瓜,傻傻的瓜瓜

    难得糊涂啊难得糊涂,糊涂着也不要清醒,给我一段代码,足以足以,阿拜彩带不要求很多,忘记一切,快乐起来,++油,奋斗吧!

public sealed class Singleton


 public static Singleton Instance
 {
  get
  {
   return SingletonCreator.instance;
  }
 }

 class SingletonCreator
 {
  // Explicit static constructor to tell C# compiler
  // not to mark type as beforefieldinit
  static Nested()
  {}

  internal static readonly Singleton instance = new Singleton();
 }
}

      使用泛型,代码变成这样:

public class SingletonProvider<T> where T : new()
{
 SingletonProvider() { }

 public static T Instance
 {
  get { return SingletonCreator.instance; }
 }

 class SingletonCreator
 {
  static SingletonCreator() { }
  internal static readonly T instance = new T();
 }
}

 抄过来看看,嘿嘿

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值