Python for the .NET developer Transcripts
Chapter: The Python Language
Lecture: C# using blocks

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of the beautiful things about
0:01 the C# language is the using statement.
0:04 Here we're creating a text file
0:06 a stream writer, that we're going to write to this JSON.
0:11 So we're creating a dictionary
0:12 and we're going to store the dictionary by serializing it
0:15 into that file, and it just says, hey, we created this file.
0:20 While we're in this block, this file is open
0:23 and ready for writing.
0:25 Here, it is closed, and flushed, and done
0:27 even if there was an exception, it's all cleaned up.
0:30 Beautiful, right?
0:31 Let's just run this real quick.
0:33 Alright, it says it created a file
0:34 let's go have a look, see what we got.
0:40 That would be in bin/debug on that core
0:43 and down here you can see here's our file.json with Michael
0:47 and the language is C#.
0:50 Pretty cool, right?
0:51 And of course that was created safely using the using block.