This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Video Player
00:00
00:00
00:00
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Learn how Visual Studio helps you write code.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now let's look at how to
write code in Visual Studio.
0:00
Here in the Editor window I
have a number of files open.
0:03
I can rearrange these tabs
by dragging them around.
0:06
Program.cs is where I want to
spend most of my time right now so
0:10
I always want to be able to find it,
even if I open a bunch of other files.
0:13
That happens a lot when I'm tracking
down a bug or exploring code.
0:17
So you can pin any of these tabs by
right-clicking the pin button here.
0:21
This moves the tab to the far
left side and keeps it there.
0:26
I don't need these other files right now.
0:30
I can close all except the ones I'm
interested in by right-clicking
0:31
on the tab I want and
clicking Close All But This.
0:35
Notice here that there is also an option
to close all but the tabs I've pinned.
0:39
If you ever want to know where
the file you are working on is located
0:44
in the file explorer, you can mouse
over it, this shows you the full path.
0:47
You can also right-click on the tab and
0:52
click Copy Full Path which copies the path
of the file to the Windows clipboard.
0:54
Or you can click Open Containing Folder,
which opens the file explorer and
0:59
selects the file.
1:04
All these things are very
handy when working with files.
1:06
Okay, now that I've cleaned
up my workspace a little,
1:11
let's take a look at some of
the features of the text editor.
1:13
One of the first things you
notice is the coloring.
1:17
Of course, the colors you use will be
different if you're using a different
1:20
color theme.
1:23
The colored text is what is
called syntax highlighting.
1:24
Comments are in green,
language keywords are blue, type names
1:27
that are not keywords are in light blue,
and strings, like this one, are in red.
1:33
Here you'll notice that these using
namespace statements are grayed out.
1:39
That's because there isn't any code
in this file using those namespaces.
1:43
Visual Studio is telling us
that we can remove these lines.
1:47
The colored line on the left shows which
lines have been changed since the last
1:51
time the file was saved.
1:55
If I save the file,
everything will turn green.
1:56
There's also a lot of information
here in the scroll bar.
1:59
This solid blue line shows where in the
file the cursor is located at the moment.
2:03
Here we see a green square.
2:07
This shows where we have
compiler warnings in the code.
2:09
They correspond to where we see
green squiggles under the text here.
2:13
Mousing over the green squiggles
shows a tool tip with the warning.
2:17
This one is telling us that the variable
greeting is assigned but not used.
2:21
Warnings are important to pay
attention to because they often mean
2:26
there's something we've forgotten to do
and there's potentially a bug in the code.
2:29
Errors show up in red.
2:34
These are things that will stop
the code from building all together.
2:36
If I delete this closing parenthesis,
2:39
you will see a red squiggly line
where the parenthesis once was.
2:42
We also see a little red square
show up here in the tool bar.
2:45
This feature is constantly making us
aware of compiler errors, and warnings,
2:49
saves us a lot of time when it comes
time to compile and run the code.
2:53
In fact, I find that I encounter
compiler errors when building my
2:57
code a lot less often now.
3:01
Visual Studio tries to reduce
typing required to write code.
3:03
It has a number of ways to do this,
for instance,
3:07
if you start typing a list of keywords or
other suggestions will appear.
3:09
It selects the one you
are most likely to use.
3:14
With the symbol selected,
3:16
just hit Tab to have Visual Studio
finish typing it for you.
3:17
As I keep typing, I get to where
I want to write a string literal.
3:21
Notice when I type the first double quote,
3:25
it automatically adds
the ending double quote.
3:27
I can keep typing my string.
3:29
When I get to the end of the string,
I can hit Tab, and
3:34
it moves the cursor to the end of
the line, so I can type the semicolon.
3:36
I'll show some more of these auto
complete features while I write another
3:40
method here.
3:43
I'll type S, T, A, Tab,
3:46
Space, S, T, Tab, the name of the method.
3:51
And open parenthesis.
3:57
See the closing parenthesis
was added automatically?
3:59
S, T, Tab, and then a variable name, and
Tab again to get to the end of the line.
4:03
Return, and then an open curly brace.
4:09
See the closing curly brace
was automatically added?
4:12
Hit Return again and the second curly
brace is moved down two lines, and
4:15
the cursor is indented.
4:19
As you can see, typing in Visual Studio's
4:22
text editor is very different than typing
in a regular word processing program.
4:24
It uses its knowledge of the symbols in
your program, conventions used in C#,
4:29
and the C# syntax and
grammar to help you speed up your coding.
4:34
For some coders,
this may take a bit to get used to.
4:38
After a while, it become second nature and
you don't even think a lot about it.
4:41
This allows you to spend your time
thinking about the problem you're trying
4:45
to solve and less about things like
spelling syntax and what things are named.
4:48
Another way Visual Studio
tries to help you
4:52
while typing is a feature
called IntelliSense.
4:55
IntelliSense helps you when you type
a dot at the end of a valid expression.
4:58
It determines what the type of the
expression to the left of the dot is and
5:03
then shows you a list of methods,
properties and
5:07
fields that you can call
from the scope you are in.
5:09
As you start typing,
5:13
it highlights the symbol that
you are most likely looking for.
5:14
You can also use the up and
down arrow keys to select the name.
5:17
When you hit Tab, period, Space or any
other character that makes sense in that
5:21
context, it types the rest of the name for
you.
5:25
If you don't want it to
type what is selected,
5:28
just hit the Escape key on your keyboard.
5:30
There are lots of other ways
Visual Studio helps with typing code
5:33
including the use of snippets and
code generators
5:36
which are more advanced than we need
to cover here in this workshop.
5:39
And of course, if you don't like
some of these code typing features,
5:43
you can always turn them off.
5:45
However, I encourage you
to experiment with them for
5:47
a while before you make that decision.
5:50
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up