17
Reply

Ho can you restrict to creating only 3 objects for a class at any time ?

Komara Reddy

Komara Reddy

Oct 17, 2016
842
0

    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++;}}} }

    Komara Reddy
    October 17, 2016
    2

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 22, 2017
    0

    By throwing error

    Mukesh Kumar
    September 04, 2017
    0

    By throw an error in construct er

    Mukesh Kumar
    September 02, 2017
    0

    by putting onstructor in if condition

    Mukesh Kumar
    August 29, 2017
    0