Is it better to use the [using] statement in C# or the [dispose] method? Does this apply to external (COM) objects?
问题 What is better, the using directive, or the dispose directive when finished with an object? using(FileStream fileStream = new FileStream( "logs/myapp.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using(StreamReader streamReader = new StreamReader(fileStream)) { this.textBoxLogs.Text = streamReader.ReadToEnd(); } } On the other hand, when I'm dealing with System.Net.Mail, I'm told I need to Dispose() of the object to release any stray locks. Is there any consistent guidance?