Can “using” with more than one resource cause a resource leak?
问题 C# lets me do the following (example from MSDN): using (Font font3 = new Font("Arial", 10.0f), font4 = new Font("Arial", 10.0f)) { // Use font3 and font4. } What happens if font4 = new Font throws? From what I understand font3 will leak resources and won't be disposed of. Is this true? (font4 won't be disposed of) Does this mean using(... , ...) should be avoided altogether in favor of nested using? 回答1: No. The compiler will generate a separate finally block for each variable. The spec (§8