Python for .NET Developers 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 the C# language is the using statement. Here we're creating a text file
0:07 a stream writer, that we're going to write to this JSON. So we're creating a dictionary and we're going to store the dictionary by serializing it
0:16 into that file, and it just says, hey, we created this file. While we're in this block, this file is open and ready for writing.
0:26 Here, it is closed, and flushed, and done even if there was an exception, it's all cleaned up. Beautiful, right? Let's just run this real quick.
0:34 Alright, it says it created a file let's go have a look, see what we got. That would be in bin/debug on that core
0:44 and down here you can see here's our file.json with Michael and the language is C#. Pretty cool, right?
0:52 And of course that was created safely using the using block.


Talk Python's Mastodon Michael Kennedy's Mastodon