Limiting number of objects for a class

I have seen in many interviewers asking about how we can limit the number of objects created for a class. This post explains how to do this in C#. This can be done using a static variable.  Static variable will be invoked before the execution of constructor and it’s value will be destroyed when associated application domain ends.

In this we discuss two methods to limit the class instance to a particular number say 5 Continue reading