在.net中利用单例模式来实现延迟加载,可用来提高程序的启动速度。即调用的时候判断对象的字段是否为空,为空则新建个对象,赋值给字段

1 private object example;
2 public object Example
3 {
4 if(example==null)
5 {
6 example=new object();
7 }
8 return example;
9 }

以上只是延迟赋值,没有实现单例,如果没记错的话,字段和属性加上 static 就可实现。

---备忘

相关文章:

  • 2021-04-10
  • 2021-08-29
  • 2022-02-05
  • 2021-09-10
  • 2021-11-29
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-08-27
相关资源
相似解决方案