title: How to delete object?
body: <p>I need to create a method of class that delete the instance.</p>
  
  <pre><code>public class Car
  {
      private string m_Color;
  
      public string Color
      {
          get { return m_Color; }
          set { m_Color = value; }
      }
  
      public Car()
      {
      }
  
      public void Delete()
      {
          /*This method will delete the instance,
          so any references to this instance will be now null*/
      }
  }
  
  class Program
  {
      static void Main( string[] args )
      {
          Car car = new Car();
  
          car.Delete();
  
          if(car==null)
              Console.WriteLine("It works.");
          else
              Console.WriteLine("It doesn't work.")
      }
  }
  </code></pre>
  
  <p>I want to know if there is any possible solution (even if it is not recommended) how to do this.</p>
  
  <p>Instance of this class will be stored in hundreds of different class. I will try to describe this, for example there will be these classes:</p>
  
  <pre><code>public class CarKey
  {
      private Car m_Car;
  
      public Car Car
      {
          get { return m_Car; }
      }
  
      public bool CarExist{ get{ return m_Car != null; } }
  
      public CarKey( Car car )
      {
          m_Car = car;
      }
  }
  
  public class Garages
  {
       private List&lt;Car&gt; m_Collection = new List&lt;Car&gt;();
  
       private int m_Size;
  
       public int Size{ get{ return m_Size; } }
  
       public Garages( int size )
       {
           for(int i=0;i&lt;size;i++)
               m_Collection.Add(null);
       }
  
       public bool IsEmpty( int garage )
       {
           return m_Collection[garage] == null;
       }
  
       public void InsertCar( Car car, int garage )
       {
            if( m_Collection[garage] != null )
              throw new Exception("This garage is full.");
  
            m_Collection[garage] = car;
       }
  
  
       public Car GetCar( int garage )
       {
           if( m_Collection[garage] == null )
             throw new Exception("There is no car, maybe it was deleted.");
  
           return m_Collection[garage];
       }
  }
  </code></pre>