Limit instances creation of a class?

前端 未结 6 1643
暖寄归人
暖寄归人 2021-01-11 16:15

I am using C#. I have created a class which can be included in any c#.net project (desktop or web based), but I want that only 10 objects will be created in that application

6条回答
  •  灰色年华
    2021-01-11 16:33

    take an static counter in the class, and throw an exception in your class constructor if count>10

提交回复
热议问题