Does the C# compiler automatically dispose of IDisposable objects?
问题 Assuming I have a method public static Rectangle DrawRectangle(Vector origin, Vector size) which returns an object of type Rectangle : IDisposable If I call only the method DrawRectangle(origin, size) , but do not assign the return value to a variable myRectangle = DrawRectangle(origin, size) , will the compiler automatically detect this and call DrawRectangle(origin, size).Dispose() , or do I have to do it myself? 回答1: There are only two scenarios I can think of where the compiler