   [C#]  Why does this class member have to be passed in by reference?
  I have a simple 3D tile class:    public class Tile3D    {   public Quadrangle[] quads;   public Vector3 position;   public Tile3D_Type type;   public Tile3D()   {  quads = new Quadrangle[6];   }    }When removing quads from this class I tried doing the following:   private void RemoveTileQuads(Tile3D tile)   {  RemoveQuad(tile.quads[0]);  // Left  RemoveQuad(tile.quads[1]);  // Right  RemoveQuad(tile.quads[2]);  // Down  RemoveQuad(tile.quads[3]);  // Up  RemoveQuad(tile.quads[4]);  // Forward  RemoveQuad(tile.quads[5]);  // Backward   }   private void RemoveQuad(Quadrangle quad)   {  quad = null;   }However, this had no effect and instead I had to pass the quad by reference:   private void RemoveTileQuads(Tile3D tile)   {  RemoveQuad(ref tile.quads[0]);  // Left  RemoveQuad(ref tile.quads[1]);  // Right  RemoveQuad(ref tile.quads[2]);  // Down  RemoveQuad(ref tile.quads[3]);  // Up  RemoveQuad(ref tile.quads[4]);  // Forward  RemoveQuad(ref tile.quads[5]);  // Backward   }   private void RemoveQuad(ref Quadrangle quad)   {  quad = null;   }The quadrangle class is just a normal class:    public class Quadrangle    {   public bool IsAlive = false;    // Quadrangles should not be alive until taken from the pool (not when created by pool)   public Texture2D Texture;   float height;  Vector3 position;// Central position   bool recreateWorld;   // Recreate world transform this frame?   Matrix rotation; // X,Y,Z axes (Right, Up, Backward/Normal)   VertexQuadBatch[] vertices;// Vertex format   float width;So why do I have to pass quadrangle using the ref keyword?   
  C# class instances are reference types, but they are passed by value. You get a copy of the callers reference, aliasing the same object.So all you are doing is setting the local parameter value to null. You need to use the ref parameter to set the caller's value to null.However, in this case wouldn't it be simpler to assign null in the caller? You could also use a loop instead of manually writing each of the values.   ;  Thanks rip-off, that makes sense.Quote:However, in this case wouldn't it be simpler to assign null in the caller? You could also use a loop instead of manually writing each of the values.This was a simple example, the RemoveQuad method is more complex. All quads aren't always removed either.   