How to create objects from a class with private constructor?

前端 未结 6 1538
花落未央
花落未央 2021-01-14 00:39

I have a class Game that is my main class and a second class Card. Class Card hast its properties and constructor private, only function init is public. Function init checks

6条回答
  •  悲&欢浪女
    2021-01-14 00:50

    public class demo
    {
        private demo()
        {
    
        }
        public static demo getObject()
        {
            return new demo();
        }
    
        public void add()
        {
    
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            demo d1 = demo.getObject();
            d1.add();
        }
    }
    

提交回复
热议问题