 Hey everybody, it's Brian and welcome to the, oh man, what are we up to? The 18th C-sharp tutorial? And we're just gonna make a new project and we're gonna make a console application. Today we're going to kick things up a notch. I said we're gonna ramp these tutorials up rather quickly and I was not joking. We're not gonna go over the normal what's a variable, what's this, what's that because well, to be honest, most of you are smart enough to understand this stuff anyways. So what we're gonna discuss today is called file input output. So first thing we need to do is use a namespace. Notice how we've been talking about namespace but we haven't actually used one. So type using and you notice little IntelliSense popped up type system. And then we want you notice all these little beautiful things that pop up. These are all namespaces. And while we probably won't cover all of these because the .NET framework is just massive, we're gonna cover a good majority of these. What we want is IO which stands for simple input output. Now in the system IO namespace, let's just copy this. I want to show you something. If you just type system IO dot you can actually just navigate the namespace and see what's in there. You see there's a lot of stuff in here. Well what the IO namespace does is well you guessed it input output. This is how you write to a file, read a listing of directories, things of that nature. So what we're gonna do today is we're just very simply going to read and write a file. So let's just do static void, we'll say write file. And we're just going to make a function to write the file and we're gonna make another function to read the file. And then we're just gonna call these, you know, in turn and we'll just make a variable. Now one thing I want to discuss about strings is if you try to do something like this, let's just say he test my doc dot txt. You notice how it just starts freaking out? Well the problem is these backslashes. That's an escape character. So what you need to do is put an at symbol in front. What that does is says this is a string literal meaning this is all one string. Not this is a string, this is a string, this is a string. Because it treats that as an escape character. Escape characters add things like hard returns, tabs, things of that nature. So if you see that at symbol in front of a string that's really all it's doing is saying ignore that slash. Then we're gonna say write file, file name, and then we want to read file, file name. Now we haven't actually done anything yet, we're just calling some functions here. So we've got our string which is our file name and we're going to write file which is gonna jump up here. And then we're going to write the file. So what we need to do here, and there's a couple ways we can do this. And we're gonna do it the easy way this time because I want to kind of slowly ease you into this. So say file, write all text. And you notice how it says string path, string contents. So we will just say file name. And we're just going to simply say hello world. Now we want to read the contents. So we want to say file, read all text. And you notice how this returns a string. We could also say read all lines which returns an array of strings. So which one do you want to do? Well it really doesn't matter. Read all text will just return all of the text, read all line will return every single line. For this tutorial we're just gonna say read all text. We're gonna say console, write line. And we want to say file, read all text. And then we need to get up a path which is just you guessed it, file name. So that in a nutshell is the simplest way of reading and writing a file. So let's run this. Uh oh, build errors. What did we do wrong here? Oh yes, simply forgot. That's one thing I do love about .NET is the debugging is first class. I have yet to find anything that even comes close. Yes, we forgot to do our console read. And there we go. We have written our file and we read it back out into the console. Now that is extremely simple input output. The next tutorial we're gonna get a little more complex but that's it for this one. This is Brian. Thank you for watching. I hope you found this educational and entertaining.