C# The 'new' keyword on existing objects

后端 未结 9 461
一整个雨季
一整个雨季 2020-12-28 13:25

I was wondering as to what happens to an object (in C#), once its reference becomes reassigned. Example:

Car c = new Car(\"Red Car\");
c = new Car(\"Blue Car         


        
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 13:57

    In case Car holds some native resources you'll want to implement IDisposable and dispose of it properly before reusing the variable.

提交回复
热议问题