From the course: Learning C#

How to run the examples - C# Tutorial

From the course: Learning C#

How to run the examples

- [Instructor] So now that we've installed and tested the dot net SDK, let's see how to run the examples in this course. Now all of the examples in this course are built as command line or console programs. This makes it easy to run them from your computer's terminal program. And since I'm on windows, I'm going to open up my command prompt program, which you see here. But if you're on a Mac or Linux computer, then use the terminal program for that operating system. So what we're going to do is run one of the finished example files. And if we look inside the exercise files folder, which I've put here on my desktop, you can see that there's a folder for finished and start examples. And if I look inside the finished folder, you'll see that there are sub folders that correspond to each chapter in this course. And there's also a folder for the starting points as well. So what I'm going to do is I'm going to close this and then I'm going to go into the folder for the examples. So that's on my desktop and that's going to be in exercise, let's make sure. Yep, so let's go into the exercise files and we'll go into finished. And then inside the finished examples I'm going to go into the overview folder and then into the hello world folder. And I'm going to type dir to show you the folder contents. So there's two files in here. There's the hello world dot CS proj. This is the project file. And then program dot CS. That's where our code is. So all I need to do to run each example is just type the command.net run when I'm in the folder at the top level of the project. So I'm going to go ahead and do that. And when I do .net run it's going to compile and build the program. And we can see here that after a few moments .net has built the app and then there's some output display down here. It says, hello world, what is your name? And I'm going to type in Joe. And then you can see the output of our first hello world program. And we'll get into that when we start the course in the next chapter, but for now just want to show you how to run these examples. Now I'm going to be using visual studio code for this course, which actually has a terminal program built in. It's one of the reasons why I like it. So if you're also using VS code then you can run the examples that way. So let me show you that. All right, so here in VS code, I'm going to start by opening up the exercise files folder, and that is on my desktop. So I'll choose that and select it. And then, once the application starts, I'll close the welcome window, and then I'll navigate into the finished overview hello world folder. And you can see here's the project and here's the code. All right, so then what I'm going to do is I'm going to right click on the hello world folder and I'm going to choose open in integrated terminal. And you can see that when I do that this terminal window opens down here in my editor and puts me right into that folder automatically. So I don't have to do all this like changing directories in the command line and all that stuff. So now I can just type .net run again. And you can see that the application runs just the way it did in the other terminal. So once again, I'll type in my name and you can see that the program runs. So either way it works fine. If you want to run it in VS code, that's great. If you want to run it in your own terminal program, that's great too. It's all up to you how you want to run the examples on your machine.

Contents