Ho can you restrict to creating only 3 objects for a class at any time ?
Komara Reddy
Create default constructor and one static field in class, every time you create object of class the default constructor get called, there you can check how many object already created based on that you can restrictExample : namespace ConsoleApplication1 {class Program{static void Main(string[] args){Employee obj = new Employee();Employee obj1 = new Employee();Employee obj2 = new Employee();Employee obj3 = new Employee();Employee obj4 = new Employee();Employee obj5 = new Employee();Employee obj6 = new Employee();Console.Read();}}class Employee{static int count = 0;public Employee(){if (count == 5){//raise error or deallocate object}else{count++;}}} }
By throwing error
By throw an error in construct er
by putting onstructor in if condition