什么是用C#单身?单身

2023-09-02 11:45:41 作者:十里画廊

pretty的直线前进的问题。

Pretty straight forward question.

什么是单身,当我应该使用它?

What is a Singleton and when should I use it?

推荐答案

一个单身是一类只允许创建自身的一个实例 - 并给出了简单,方便地访问表示实例。该单premise是整个软件开发的模式。

A singleton is a class which only allows one instance of itself to be created - and gives simple, easy access to said instance. The singleton premise is a pattern across software development.

有一个C#实现实现在C#中的Singleton模式你所需要知道的覆盖最 - 包括对一些好的建议线程安全

There is a C# implementation "Implementing the Singleton Pattern in C#" covering most of what you need to know - including some good advice regarding thread safety.

说实话,这是非常罕见的,你需要实现一个单 - 在我看来,它应该是这些东西你应该知道的一个,即使它不使用过于频繁

To be honest, It's very rare that you need to implement a singleton - in my opinion it should be one of those things you should be aware of, even if it's not used too often.