Amol Sarkate

Amol Sarkate

  • NA
  • 634
  • 156.7k

how to destroy current object from constructor..?

Mar 25 2017 3:21 AM
if we create a class and fro that class we created  six   instance  we  want only five  see example in comment section w ahve to  destroy  current object how like 
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)
{
   // here we need to distroy na  current object 
}
else
{
count++;
}
}
}
}
 

Answers (5)