From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../prerequisites/using-and-dispose/index.html | 444 +++++++++++++++++++++ 1 file changed, 444 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html') diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html new file mode 100644 index 0000000..1b06644 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + + Using And Dispose | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Using and Dispose

+

Whenever you have an object the implements IDisposable, you need to dispose of the resource when you're done with it. Most classes that use unmanaged resources will implement IDisposable. This means a lot of classes in the System.IO namespace will need to be disposed of.

+

The best practice to dispose of an object when you're done with it is to wrap the code in a using block. When the using block exits, the resource will automatically be disposed of as soon as possible.

+
using (var stream = new MemoryStream())
+{
+	// Use the stream.
+}
+// The stream will be disposed of as soon as possible.
+
+

If you need to keep keep it around for a while and dispose of it later, using does some error handling for you, so it's still a good idea to use it instead of calling Dispose directly. There is some debate on whether this is a good idea because it doesn't show intent.

+
var stream = new MemoryStream();
+// Later in a different part of your code.
+using (stream) { }
+
+ +
+
+
+
+ +

+ + + + + + + + + + + -- cgit v1.1-26-g67d0