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

问题描述

什么是私有构造的C#的需求?
我得到了它作为一个C#测试的问题。

What is the need of private constructor in C#?I got it as a question for a C# test.

推荐答案

例如,如果你有一个类只有应通过工厂方法来创建。或者,如果你有构造重载,其中一些只能由其他的构造方法。也许其他的原因,以及=)

For example if you have a class that should only be created through factory methods. Or if you have overloads of the constructor, and some of them should only be used by the other constructors. Probably other reasons as well =)

这篇关于什么是私有构造的C#的需求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:23