Locked lesson.
About this lesson
We see what happens when we run our first program, "Hello World"
Exercise files
Download this lesson’s related exercise files.
4 - First Program Hello World .docx60.7 KB 4 - First Program Hello World SOLUTION.docx
57.7 KB
Quick reference
First Program: Hello World
The first program that all new coders write is always "Hello World!"
When to use
You'll only do this once when you first learn a new programming language.
Instructions
Visual Studio will write the code for you, but the key line of code that makes the text "Hello World!" appear is:
Console.WriteLine("Hello World!");
Login to download- 00:04 All right, let's look at this first Hello World program.
- 00:07 So like I said in the last video, Hello World is always the first program that any
- 00:10 coder creates in a programming language when you're starting to learn.
- 00:13 It's just historically that first program every coder has ever made.
- 00:17 So this is the C Sharp version of Hello World.
- 00:20 And what we want to do here is just output onto the screen the words Hello World.
- 00:25 So you see we've got this program,
- 00:27 and there's already a lot of code in here that's been created for us.
- 00:31 And we can click on these little things here to expand and contract.
- 00:36 And inside of here, expand and contract, and same thing inside of here.
- 00:40 And you notice things are broken apart by these squiggly brackets, right?
- 00:44 That's what's expanding and
- 00:46 contracting anytime we click one of these little minus signs here.
- 00:50 This is the outer one, it contains everything, so boom, that all disappears.
- 00:55 Generally, probably won't be messing with these little subtraction and
- 00:58 addition signs to do this sort of thing, but you can if you want.
- 01:02 And so here we have, we're using System, that's something we're importing.
- 01:05 We have this namespace is HelloWorld, and then we have a class with program.
- 01:09 Inside of here, we have define some stuff here.
- 01:13 And we'll get into what these things are later.
- 01:15 And then this is basically what we want the program to do.
- 01:18 We want to write a line onto the console that says Hello World.
- 01:22 You'll notice that this line ends with a semicolon.
- 01:24 Most lines will end with a semicolon, and we'll see that going forward.
- 01:28 And that's all there is to it.
- 01:29 So this console is where our program is going to run and
- 01:32 where it's going to do whatever we've told it to do.
- 01:35 In this case, we're just writing a line that says Hello World onto the console.
- 01:38 So all right, that's it, there's nothing we have to do here.
- 01:41 We're not actually writing any code in this video because it's all been
- 01:43 written for us.
- 01:44 But it's still a very big first step for all coders to run their first program.
- 01:48 So how do we run this guy?
- 01:49 Well, we can come up here, and we see this little play button here, right?
- 01:52 And if I click here, you can see there's Debug Properties and
- 01:57 then there's the thing itself.
- 01:59 So what we just want to do is click this little green arrow, boom.
- 02:02 And you can see down here it's starting to build our project.
- 02:05 Does a thing, kind of flashes a little, and then boom, this thing pops up,
- 02:09 this is the console, right?
- 02:11 And you can see right here it says Hello World,
- 02:13 it's been outputted onto the screen.
- 02:15 And that's all there is to it.
- 02:16 So congratulations, you've done your first program.
- 02:19 I know it's not much of a program, but.
- 02:21 And this is, like I said, the first program that anybody ever creates
- 02:24 when they start learning computer programming of any kind,
- 02:26 any sort of programming language.
- 02:27 It's always the Hello World program, and it's always this silly, but kind of cool.
- 02:32 So you'll notice right here it says press any key to close this window.
- 02:34 So if I press a key on my keyboard, that disappears.
- 02:37 If we run this guy again, it pops up again.
- 02:40 This time I can click this X, that also closes it, right?
- 02:43 So really either way, it doesn't really matter, whatever you prefer.
- 02:50 In this instance, it really doesn't matter at all.
- 02:52 And that's all there is to it.
- 02:53 So you'll notice down here, this is sort of the debug screen, and
- 02:57 you see it says right there debug.
- 03:00 Anytime we run a program with C Sharp, it's going to debug it going forward.
- 03:06 And here we'll see if we take this guy off, all of a sudden,
- 03:09 uh-oh, things start flashing down here.
- 03:12 There's a little x that says error.
- 03:14 We come up here, there's a angry yellow bar here.
- 03:19 And if we hover over this and then click this, we get sort of more information
- 03:23 about what's going on here to help us determine what the problem is and
- 03:27 how to fix it.
- 03:28 So I can come back here, and let's just run this guy and see what happens.
- 03:32 So boom, right here it says there are build errors.
- 03:35 Down here you can see build started, done building, build 0 succeeded, 1 failed.
- 03:41 See right down here it says failed because we have errors that won't let the program
- 03:45 continue.
- 03:46 So would you like to continue and run the latest successful build?
- 03:49 We could try Yes, and in this case, it actually did still work.
- 03:53 But normally, you would go ahead and click No, take a look at your code,
- 03:57 figure out what's wrong, and then fix it.
- 03:59 In our case, we could put the semicolon back, no big deal.
- 04:02 We could run this guy again, no errors this time, and boom, it runs successfully.
- 04:07 We can close this, and we're good to go.
- 04:09 So that's our first program, the Hello World program.
- 04:11 Not much to it, of course, but
- 04:13 one of those things you still have to get through.
- 04:16 In the next video, we're going to jump in and start to actually learn C Sharp, and
- 04:20 we're going to start to look at variables.
Lesson notes are only available for subscribers.