How to delete an array in c#?

Say you call:

 void Foo(){
     int[] a = new int[5];

In C# there is no way to undefine the variable a. That means a will be defined in Foo even if you set a to null.
However, at the end of Foo a will fall out of scope. That means no code can reference it, and the garbage collector will take care of freeing the memory for you the next time it runs, which might not be for a long time.

Leave a Comment