什么是 C# 中的单例? [英] What is a singleton in C#?

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

问题描述

什么是单例,我应该在什么时候使用它?

What is a Singleton and when should I use it?

推荐答案

单例是一个类,它只允许创建自己的一个实例 - 并提供对所述实例的简单、轻松的访问.单例前提是跨软件开发的一种模式.

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# 中实现单例模式",涵盖了大部分您需要了解的内容 - 包括一些关于线程安全的好建议.

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天全站免登陆