本文介绍了[不是问题]私人建设者,请举例说明。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是私有构造函数?

如何使用它?

请解释一下。

What is private constructor?
How it can be used?
Please explain this.

推荐答案

class Demo
   {
       public static void Main()
       {
           // We can access an instance of this object that was created.
           // ... The private constructor was used.
           Employee test = Employee.empPrivate;
           // These statements show that the class is usable.
           Console.WriteLine(Employee.property);
           Console.ReadLine();
       }

   }
   class Employee
   {
       public static decimal property = 0;
       private Employee(int value)
       {
           property = value;
       }
       public static Employee empPrivate = new Employee(500000);
       static void testMethod()
       {
           Console.WriteLine("You are calling test method");
       }
   }



这篇关于[不是问题]私人建设者,请举例说明。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:15