什么是用C#单身? [英] What is a singleton in C#?

查看:137
本文介绍了什么是用C#单身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

这篇关于什么是用C#单身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆