1
00:00:00,740 --> 00:00:06,400
In this video we're going to be creating our first console application.

2
00:00:06,590 --> 00:00:07,930
So let's get started right away.

3
00:00:07,940 --> 00:00:16,010
Bring up Visual Studio and then go to create a new project and then we can narrow it down to see a console

4
00:00:16,100 --> 00:00:18,740
app so maybe you did that's already maybe you didn't.

5
00:00:18,770 --> 00:00:24,210
That's fine but you can always just go to see sharp windows and then select console in this third one.

6
00:00:24,260 --> 00:00:29,870
Or you can just search console and then it will narrow it down for you know we're going to start off

7
00:00:29,870 --> 00:00:36,010
with a dot net core console up this time so select console update on it core fleet next.

8
00:00:36,350 --> 00:00:38,990
And then we name it differently this time.

9
00:00:38,990 --> 00:00:41,960
So we have a project name somewhere to call this one.

10
00:00:41,960 --> 00:00:43,850
Hello world.

11
00:00:43,850 --> 00:00:45,350
That's the name of the project.

12
00:00:45,350 --> 00:00:50,750
Well then I'm went to have multiple projects underneath my solution so I don't want my solution to be

13
00:00:50,750 --> 00:00:52,040
called Hello World.

14
00:00:52,040 --> 00:00:56,500
And then I'd want to have multiple projects with other names so naming is very important.

15
00:00:56,540 --> 00:00:58,880
It helps you to identify exactly what you're seeing.

16
00:00:59,000 --> 00:01:02,830
And you know it just makes life easier for too much.

17
00:01:02,870 --> 00:01:09,140
So I'm going to call this entire solution console programming because once again we're going to have

18
00:01:09,170 --> 00:01:13,910
this solution with a bunch of projects geared towards us learning console programming.

19
00:01:13,940 --> 00:01:17,420
So the solution name once again is console programming.

20
00:01:17,420 --> 00:01:21,160
But the project that we're creating right now is called Hello world.

21
00:01:21,230 --> 00:01:26,100
So I am just going to click Create and allow Visual Studio to do its thing.

22
00:01:26,220 --> 00:01:30,950
No one Visual Studio launches our project you're going to see something very very very unique.

23
00:01:30,950 --> 00:01:36,200
You notice that it's already launched our program that we just said we're going to write it is printing

24
00:01:36,230 --> 00:01:38,300
hello world to the console.

25
00:01:38,330 --> 00:01:44,210
No I just want to before we look at the code I just want to point out that a solution is going to solution

26
00:01:44,210 --> 00:01:48,830
Explorer is going to have a slightly different look say if you use the dot net framework.

27
00:01:48,830 --> 00:01:55,670
I know you're using alternate core then the files the label may look slightly different but ultimately

28
00:01:55,970 --> 00:02:01,970
it's the same set of concepts you have your program dot see this file and that is the one that comes

29
00:02:01,970 --> 00:02:08,330
open when Visual Studio launches and we see that we have a class called program and it has a function

30
00:02:08,330 --> 00:02:15,620
called mean and so mean gets called once your application launches whatever is inside of our main function

31
00:02:15,650 --> 00:02:17,620
is what gets fired.

32
00:02:17,630 --> 00:02:18,680
All right.

33
00:02:18,680 --> 00:02:24,830
If you expand dependencies then you'll see they have dependencies frameworks and then basically any

34
00:02:24,890 --> 00:02:27,050
libraries that you may want.

35
00:02:27,140 --> 00:02:32,900
So sometimes you want to do a particular thing and somebody has what they call a library that they've

36
00:02:32,900 --> 00:02:34,050
done it in already.

37
00:02:34,070 --> 00:02:38,210
You can actually include them and then use the library but that's for later on.

38
00:02:38,300 --> 00:02:41,000
I'm just giving you an appreciation of what you're looking at right.

39
00:02:41,000 --> 00:02:41,530
No.

40
00:02:41,570 --> 00:02:44,630
So no we'd need to see exactly what happened.

41
00:02:44,630 --> 00:02:54,620
So once again our code is console dot right line and then we open the briefs and then we have quotation

42
00:02:54,620 --> 00:02:55,350
marks.

43
00:02:55,400 --> 00:03:01,920
That's a Hello World Class quotation marks floors brace and then semicolon.

44
00:03:01,910 --> 00:03:04,550
So I'm going to explain what each token means.

45
00:03:04,550 --> 00:03:07,780
But I just want us to see how this works first.

46
00:03:07,790 --> 00:03:13,790
So once again to execute I'm just going to go and click the Start button or we can just press f five

47
00:03:13,790 --> 00:03:18,580
on our keyboard we let it build all right.

48
00:03:18,910 --> 00:03:24,180
And then we get our consoles so our console once again looks something like a command prompt.

49
00:03:24,190 --> 00:03:30,650
If you ever had to use Come on problems you know that little black box wary of the type and run commands.

50
00:03:30,680 --> 00:03:32,770
Well that's what a console program is.

51
00:03:32,770 --> 00:03:38,740
So we're seeing here Microsoft studio Microsoft Visual Studio sorry Debo console.

52
00:03:38,860 --> 00:03:42,220
And then we see that it's printing hello world.

53
00:03:42,310 --> 00:03:45,640
And then it gives us some data all where it's printing it from.

54
00:03:45,760 --> 00:03:53,290
And you know it will automatically close when debugging and press any key to close this window so I

55
00:03:53,290 --> 00:03:58,960
can just press enter and that window will disappear and we're right back where we started.

56
00:03:58,960 --> 00:04:03,010
Now let me take the time to explain exactly what is being written here.

57
00:04:03,010 --> 00:04:08,510
Notice one that visual studio kind of tries to give you color coding you see that it's quite colorful.

58
00:04:08,500 --> 00:04:10,130
You have blue takes it wide takes.

59
00:04:10,140 --> 00:04:10,940
You have.

60
00:04:11,200 --> 00:04:17,920
I don't know what color that is any kind of yellowish looking text your code hinting sorry your color

61
00:04:17,920 --> 00:04:22,510
coding might be different based on the theme that you're using.

62
00:04:22,510 --> 00:04:28,150
So if you're in the light theme or in the blue theme then you're color coding may not be the same as

63
00:04:28,150 --> 00:04:33,190
I have it here but just have an appreciation for what gets color coded.

64
00:04:33,190 --> 00:04:39,090
So we have namespace namespace refers to the pretty much the project.

65
00:04:39,310 --> 00:04:41,590
And then by extension the folder in the project.

66
00:04:41,590 --> 00:04:46,930
So if we had a folder in this project with a class file in there then the namespace would be Hello World

67
00:04:47,110 --> 00:04:48,810
dot dot folder name.

68
00:04:48,820 --> 00:04:52,240
So program six is directly inside of our project.

69
00:04:52,270 --> 00:04:55,120
So the namespace is just hello world.

70
00:04:55,120 --> 00:04:55,910
All right.

71
00:04:56,200 --> 00:04:57,330
We have a class.

72
00:04:57,340 --> 00:05:04,360
So our class is a collection of what we call properties and functions but I'm not going to teach classes

73
00:05:04,360 --> 00:05:04,870
just yet.

74
00:05:04,890 --> 00:05:11,230
But our first and major class is class program because that's the first thing that gets fired when a

75
00:05:11,230 --> 00:05:13,060
consulate up is going to run.

76
00:05:13,060 --> 00:05:19,590
And then inside of program we have static void Main and it takes some args.

77
00:05:19,600 --> 00:05:20,020
Right.

78
00:05:20,650 --> 00:05:26,440
So I don't want to get into too much detail about what the args means but just know that if you're going

79
00:05:26,440 --> 00:05:34,480
to modify anything in this file do not modify the class name and do not modify the main function you

80
00:05:34,480 --> 00:05:40,740
can do any bit of changes you want inside of here inside off the main function and we know where we're

81
00:05:40,750 --> 00:05:44,420
inside because you see the open brace and the closed brace.

82
00:05:44,500 --> 00:05:50,620
I notice it's kind of hinting where the brace closes it's trying to do all of that for you to help you

83
00:05:50,680 --> 00:05:54,310
not make certain mistakes or at least find them quickly.

84
00:05:54,340 --> 00:06:01,060
So the namespace has an open brace and a closed brace and inside of those we have the class and that

85
00:06:01,090 --> 00:06:04,210
opens and closes and then instead of the function.

86
00:06:04,210 --> 00:06:10,150
So this is a function in all functions because you have the open brace and the floors brace instead

87
00:06:10,150 --> 00:06:11,960
of the main function.

88
00:06:12,170 --> 00:06:14,590
Well you have currently braces a I have breeze.

89
00:06:14,590 --> 00:06:15,660
So our power indices.

90
00:06:15,690 --> 00:06:20,670
So sometimes I use them interchangeably but I just realized that I use them slightly interchangeably.

91
00:06:20,680 --> 00:06:26,670
So we have curly braces and then we have the regular braces are the parentheses.

92
00:06:26,680 --> 00:06:27,030
All right.

93
00:06:27,340 --> 00:06:33,400
So we know functions because they have parentheses and they may or may not have values inside of the

94
00:06:33,400 --> 00:06:34,170
open and closed.

95
00:06:34,170 --> 00:06:38,100
So in this case mean has values.

96
00:06:38,440 --> 00:06:40,010
And we don't have to trouble that.

97
00:06:40,140 --> 00:06:45,660
And then after declaring our function we have open curly brace and close curly brace.

98
00:06:45,670 --> 00:06:49,910
Then we define what this function should do inside of those braces.

99
00:06:49,930 --> 00:06:54,580
In this case we said do do a print.

100
00:06:54,580 --> 00:06:56,890
So the console that says hello world.

101
00:06:57,310 --> 00:07:01,150
So notice we have class and we have a function.

102
00:07:01,150 --> 00:07:06,040
Notice the color coding program is a class and domain is a function.

103
00:07:06,040 --> 00:07:11,800
I'm pointing that out because if you look at the color coding realize that console is a class the word

104
00:07:11,800 --> 00:07:14,310
console is a class and right.

105
00:07:14,320 --> 00:07:19,900
Line is a function and we know functions because one the color coding may look the same.

106
00:07:19,900 --> 00:07:21,620
And if it doesn't for you that's fine.

107
00:07:21,760 --> 00:07:29,350
But we need to know our function in any C sharp code that you're looking at is to see that it has parentheses

108
00:07:29,410 --> 00:07:32,380
afterwards whether or not it has values in there.

109
00:07:32,440 --> 00:07:33,830
That's a different story.

110
00:07:33,880 --> 00:07:39,820
So I could actually see bright line and then that would just be quiet.

111
00:07:39,820 --> 00:07:40,220
OK.

112
00:07:40,240 --> 00:07:40,660
So right.

113
00:07:40,660 --> 00:07:44,620
Line is a function because it says the open and close parentheses.

114
00:07:44,770 --> 00:07:49,200
And if I wanted to define the text that's I want to return to the console.

115
00:07:49,210 --> 00:07:55,510
So literally seeing this is the console call the console and write the line that I am putting inside

116
00:07:55,600 --> 00:07:59,130
of the open and close braces or parentheses.

117
00:07:59,160 --> 00:08:01,330
So then I'm going to put my Kindle world.

118
00:08:01,480 --> 00:08:04,330
And that is how our program came.

119
00:08:04,330 --> 00:08:04,960
All right.

120
00:08:04,990 --> 00:08:10,540
No I want to annotate this code because you know where I'm starting C Sharp I want to look at it tomorrow

121
00:08:10,600 --> 00:08:16,420
and remember that all oh that's what was happening here so I can just put in what we call a comment

122
00:08:16,450 --> 00:08:18,530
by using slush.

123
00:08:18,570 --> 00:08:19,230
All right.

124
00:08:19,230 --> 00:08:22,640
And then I can type anything I want someone to see.

125
00:08:22,640 --> 00:08:27,240
Printing to console screen.

126
00:08:27,240 --> 00:08:29,260
So that's our print to the console screen.

127
00:08:29,310 --> 00:08:31,710
You can use the slash slash.

128
00:08:31,750 --> 00:08:32,010
Do.

129
00:08:32,070 --> 00:08:37,140
If you wanted to write a paragraph maybe you wanted to be a bit more explicit about what everything

130
00:08:37,140 --> 00:08:37,670
is.

131
00:08:37,680 --> 00:08:41,190
Then you can use the slash then an asterisk.

132
00:08:41,190 --> 00:08:45,280
And then in between those you can have as many lines as you need.

133
00:08:45,280 --> 00:08:45,620
All right.

134
00:08:45,630 --> 00:08:52,110
Just writing some random stuff and then you just make sure that you close it with the asterisk and the

135
00:08:52,110 --> 00:08:53,310
slash.

136
00:08:53,310 --> 00:08:54,030
All right.

137
00:08:54,030 --> 00:08:54,540
No.

138
00:08:54,540 --> 00:08:59,700
You'll notice that when when I'm showing you guys how to do things I'm always open and close at the

139
00:08:59,700 --> 00:09:00,270
same time.

140
00:09:00,280 --> 00:09:04,710
And that's avoid making the mistake of forgetting to close it.

141
00:09:04,740 --> 00:09:10,500
So sometimes we get carried away and we start writing code and we open the codebase and write and write

142
00:09:10,500 --> 00:09:12,890
and write and we don't close occurring libraries.

143
00:09:12,930 --> 00:09:17,160
And then later all we're getting errors that we're wondering why are we getting errors because everything

144
00:09:17,160 --> 00:09:18,110
looks OK.

145
00:09:18,180 --> 00:09:22,710
So I'm just going to show you what I mean by getting arrows and whole visual studio goes about showing

146
00:09:22,710 --> 00:09:24,040
you that you have arrows.

147
00:09:24,060 --> 00:09:32,190
So if I forget to close a brace and maybe I forget the part indices I notice every line ends a semicolon.

148
00:09:32,190 --> 00:09:34,530
But when we have multiple lines up pay more attention to that.

149
00:09:34,890 --> 00:09:41,400
So when you see that some lines start appearing so any average lines in visual do that's never a good

150
00:09:41,400 --> 00:09:41,940
thing.

151
00:09:42,000 --> 00:09:45,000
They can appear because the syntax is incorrect.

152
00:09:45,360 --> 00:09:48,380
So the red line here is saying that hey you know something is wrong.

153
00:09:48,390 --> 00:09:51,660
I'm not entirely sure what but something is wrong somewhere.

154
00:09:51,660 --> 00:09:57,360
I can always go to the error list and then it will kind of tell me that there is an expected talk in

155
00:09:57,360 --> 00:09:57,840
somewhere.

156
00:09:57,840 --> 00:10:02,460
So if I double click that it will kind of bring me to the line that the arrow is that.

157
00:10:02,580 --> 00:10:04,990
But this is not quite where the arrow is.

158
00:10:05,010 --> 00:10:10,200
However I can debug this and see that OK when I click this close one it's matching.

159
00:10:10,320 --> 00:10:14,440
So this goes one which is inaccurate because I have a curly brace here.

160
00:10:14,480 --> 00:10:16,610
I know when I click this one it's matching to this.

161
00:10:16,620 --> 00:10:22,890
So that means I created braces missing somewhere so I can just press enter and then I can put the curly

162
00:10:22,890 --> 00:10:24,960
brace and notice so everything realign.

163
00:10:24,980 --> 00:10:30,660
So visas to do it actually realign everything because then it realizes OK so you're closing this one

164
00:10:30,660 --> 00:10:30,930
no.

165
00:10:30,930 --> 00:10:37,320
So let me just realign and reinvent everything so you can see exactly where your code starts and stops

166
00:10:37,620 --> 00:10:43,730
indentation is very important it makes the code look clean and readable two more things.

167
00:10:43,740 --> 00:10:49,830
Notice that we have a little asterisk beside the program name or the code file name rather and that

168
00:10:49,890 --> 00:10:54,990
asterisk is just an indicator that this file has been modified so you can always just know which file

169
00:10:54,990 --> 00:10:56,190
has not been saved.

170
00:10:56,250 --> 00:11:00,310
When you look at the file name the tab and you see that asterisk.

171
00:11:00,420 --> 00:11:07,860
You can always save it save all if you have multiple files or if you've made modifications and you click

172
00:11:07,860 --> 00:11:13,950
run then it will automatically see automatically recompile and then allow you to proceed.

173
00:11:13,980 --> 00:11:16,870
So if I have some legal characters here.

174
00:11:16,940 --> 00:11:17,400
All right.

175
00:11:17,400 --> 00:11:24,570
And we just looked at arrows I see red lines maybe I thought I wrote the code properly but Visual Studio

176
00:11:24,570 --> 00:11:30,180
sees it as illegal then it's going to one allow me to hover over it and give me potential fixes.

177
00:11:30,180 --> 00:11:32,380
So I went to dropdown this.

178
00:11:32,510 --> 00:11:37,320
This is the light bulb and it's going to suggest some things to me know the suggestions are usually

179
00:11:37,320 --> 00:11:43,920
like grasping at straws because there are arrows that business to do knows about that maybe you declared

180
00:11:43,920 --> 00:11:48,420
something improperly then it will say Oh I see that you declare this but you didn't do this step do

181
00:11:48,420 --> 00:11:51,560
you want me to do it for you then you say sure and it does it for you.

182
00:11:51,570 --> 00:11:55,690
However in this situation this is random takes the results to do doesn't know what to do.

183
00:11:55,710 --> 00:11:59,730
So no none of these suggestions will really fix the problem.

184
00:11:59,730 --> 00:12:05,490
Another thing to note is that if I tried to execute well there are arrows it will do the build and then

185
00:12:05,490 --> 00:12:07,540
it will tell me that there were arrows.

186
00:12:07,590 --> 00:12:09,430
Do you want to run the last successful build.

187
00:12:09,810 --> 00:12:14,790
I tend to always click No because it doesn't make sense I run the last successful belief I'm trying

188
00:12:14,790 --> 00:12:17,700
to build my current bits of code so you click No.

189
00:12:17,820 --> 00:12:23,220
And then it will kind of show you the arrow pin telling you that you have some arrows there's a semicolon

190
00:12:23,460 --> 00:12:24,360
expected.

191
00:12:24,630 --> 00:12:24,990
All right.

192
00:12:24,990 --> 00:12:30,030
So at least it said to me that if you're going to write code directed properly but then the arrow list

193
00:12:30,030 --> 00:12:34,830
is still telling me that there are things missing something here that they cannot cope with.

194
00:12:34,830 --> 00:12:43,810
So if I remove this or I can just comment it out make it you know or let me use the other comment so

195
00:12:44,260 --> 00:12:45,580
I just come into to.

196
00:12:45,670 --> 00:12:50,640
So that's one way to comment and this is another way to comment and then order is restored.

197
00:12:50,660 --> 00:12:54,430
And if you look down there they're a little visual cues along the way to tell you how many issues you

198
00:12:54,430 --> 00:12:55,050
have there too.

199
00:12:55,080 --> 00:12:57,650
I mean no issues phoned.

200
00:12:57,640 --> 00:13:03,910
No that I fixed my arrows I'm just going to run my console application once more and then we see that

201
00:13:03,910 --> 00:13:10,960
we have our hello world printing to the screen once again so I can press enter if I ever wanted to find

202
00:13:10,960 --> 00:13:12,950
this project and find the files.

203
00:13:12,960 --> 00:13:17,980
You know I have the project I have the solution of the project but I don't want to open it in visual

204
00:13:17,980 --> 00:13:20,200
studio maybe I want to put it on a flash drive.

205
00:13:20,200 --> 00:13:25,740
I want to physically move it to some storage device so that I can use it on another machine.

206
00:13:25,870 --> 00:13:33,280
Then we can easily just the right click solution and then you'll see open file in file explorer.

207
00:13:33,310 --> 00:13:40,090
So when I do that it launches my file explorer showing me this file and I'm going to see if I can zoom

208
00:13:40,090 --> 00:13:42,920
in a bit so you can see what the files look like better.

209
00:13:42,940 --> 00:13:47,080
So then this is the most timeless logo in the Dutton community.

210
00:13:47,080 --> 00:13:50,260
This is the logo that represents the solution file.

211
00:13:50,260 --> 00:13:56,830
Once you double click the solution file it will launch Visual Studio and basically launch the projects

212
00:13:56,890 --> 00:13:58,690
that are inside of that solution.

213
00:13:58,720 --> 00:14:02,710
So that's one quick way to get back to your project that you're working on.

214
00:14:02,710 --> 00:14:06,040
You just find the physical location where you started.

215
00:14:06,070 --> 00:14:11,140
You double click the solution file and then it will launch Visual Studio with all of the code that you've

216
00:14:11,140 --> 00:14:11,890
written.

217
00:14:11,890 --> 00:14:14,650
Notice hello world is in its own folder.

218
00:14:14,650 --> 00:14:16,930
And that's because it is a project.

219
00:14:16,930 --> 00:14:22,720
So each project will get put in its own folder and all of them will be in one folder together with the

220
00:14:22,720 --> 00:14:24,880
name of the solution.

221
00:14:24,880 --> 00:14:27,420
So the solution was console programming.

222
00:14:27,430 --> 00:14:28,750
It created a folder.

223
00:14:28,750 --> 00:14:31,830
Then he gave me a solution file notice the extension.

224
00:14:31,840 --> 00:14:37,990
That s a n and then for each project it gives me a folder with that name.

225
00:14:37,990 --> 00:14:40,180
So like I said the naming is very important.

226
00:14:40,180 --> 00:14:45,500
So those names are manifesting outside of Visual Studio.

227
00:14:45,580 --> 00:14:49,720
And then if I look inside this folder and want to see a bunch of little of the files.

228
00:14:49,750 --> 00:14:52,600
Well we'll get back to those files on what they're really about.

229
00:14:52,600 --> 00:14:58,000
That's it for building a Hello World console application and understanding Visual Studio a bit more.

230
00:14:58,000 --> 00:15:05,650
Next we look at how we write a program to receive data from a user and print something back to the screen.
