1 00:00:00,370 --> 00:00:03,361 Now let's look at how to write code in Visual Studio. 2 00:00:03,361 --> 00:00:06,410 Here in the Editor window I have a number of files open. 3 00:00:06,410 --> 00:00:10,116 I can rearrange these tabs by dragging them around. 4 00:00:10,116 --> 00:00:13,481 Program.cs is where I want to spend most of my time right now so 5 00:00:13,481 --> 00:00:17,780 I always want to be able to find it, even if I open a bunch of other files. 6 00:00:17,780 --> 00:00:21,190 That happens a lot when I'm tracking down a bug or exploring code. 7 00:00:21,190 --> 00:00:26,050 So you can pin any of these tabs by right-clicking the pin button here. 8 00:00:26,050 --> 00:00:28,810 This moves the tab to the far left side and keeps it there. 9 00:00:30,100 --> 00:00:31,830 I don't need these other files right now. 10 00:00:31,830 --> 00:00:35,500 I can close all except the ones I'm interested in by right-clicking 11 00:00:35,500 --> 00:00:38,540 on the tab I want and clicking Close All But This. 12 00:00:39,960 --> 00:00:44,420 Notice here that there is also an option to close all but the tabs I've pinned. 13 00:00:44,420 --> 00:00:47,950 If you ever want to know where the file you are working on is located 14 00:00:47,950 --> 00:00:52,760 in the file explorer, you can mouse over it, this shows you the full path. 15 00:00:52,760 --> 00:00:54,580 You can also right-click on the tab and 16 00:00:54,580 --> 00:00:59,880 click Copy Full Path which copies the path of the file to the Windows clipboard. 17 00:00:59,880 --> 00:01:04,420 Or you can click Open Containing Folder, which opens the file explorer and 18 00:01:04,420 --> 00:01:06,150 selects the file. 19 00:01:06,150 --> 00:01:08,660 All these things are very handy when working with files. 20 00:01:11,031 --> 00:01:13,536 Okay, now that I've cleaned up my workspace a little, 21 00:01:13,536 --> 00:01:16,270 let's take a look at some of the features of the text editor. 22 00:01:17,470 --> 00:01:20,370 One of the first things you notice is the coloring. 23 00:01:20,370 --> 00:01:23,410 Of course, the colors you use will be different if you're using a different 24 00:01:23,410 --> 00:01:24,630 color theme. 25 00:01:24,630 --> 00:01:27,960 The colored text is what is called syntax highlighting. 26 00:01:27,960 --> 00:01:33,180 Comments are in green, language keywords are blue, type names 27 00:01:33,180 --> 00:01:37,630 that are not keywords are in light blue, and strings, like this one, are in red. 28 00:01:39,460 --> 00:01:43,740 Here you'll notice that these using namespace statements are grayed out. 29 00:01:43,740 --> 00:01:47,610 That's because there isn't any code in this file using those namespaces. 30 00:01:47,610 --> 00:01:50,060 Visual Studio is telling us that we can remove these lines. 31 00:01:51,110 --> 00:01:55,109 The colored line on the left shows which lines have been changed since the last 32 00:01:55,109 --> 00:01:56,411 time the file was saved. 33 00:01:56,411 --> 00:01:58,710 If I save the file, everything will turn green. 34 00:01:59,900 --> 00:02:03,170 There's also a lot of information here in the scroll bar. 35 00:02:03,170 --> 00:02:07,910 This solid blue line shows where in the file the cursor is located at the moment. 36 00:02:07,910 --> 00:02:09,720 Here we see a green square. 37 00:02:09,720 --> 00:02:13,320 This shows where we have compiler warnings in the code. 38 00:02:13,320 --> 00:02:16,220 They correspond to where we see green squiggles under the text here. 39 00:02:17,490 --> 00:02:21,740 Mousing over the green squiggles shows a tool tip with the warning. 40 00:02:21,740 --> 00:02:26,600 This one is telling us that the variable greeting is assigned but not used. 41 00:02:26,600 --> 00:02:29,910 Warnings are important to pay attention to because they often mean 42 00:02:29,910 --> 00:02:34,630 there's something we've forgotten to do and there's potentially a bug in the code. 43 00:02:34,630 --> 00:02:36,420 Errors show up in red. 44 00:02:36,420 --> 00:02:39,680 These are things that will stop the code from building all together. 45 00:02:39,680 --> 00:02:42,110 If I delete this closing parenthesis, 46 00:02:42,110 --> 00:02:45,990 you will see a red squiggly line where the parenthesis once was. 47 00:02:45,990 --> 00:02:49,710 We also see a little red square show up here in the tool bar. 48 00:02:49,710 --> 00:02:53,684 This feature is constantly making us aware of compiler errors, and warnings, 49 00:02:53,684 --> 00:02:57,770 saves us a lot of time when it comes time to compile and run the code. 50 00:02:57,770 --> 00:03:01,520 In fact, I find that I encounter compiler errors when building my 51 00:03:01,520 --> 00:03:03,560 code a lot less often now. 52 00:03:03,560 --> 00:03:07,021 Visual Studio tries to reduce typing required to write code. 53 00:03:07,021 --> 00:03:09,524 It has a number of ways to do this, for instance, 54 00:03:09,524 --> 00:03:14,070 if you start typing a list of keywords or other suggestions will appear. 55 00:03:14,070 --> 00:03:16,770 It selects the one you are most likely to use. 56 00:03:16,770 --> 00:03:17,890 With the symbol selected, 57 00:03:17,890 --> 00:03:21,930 just hit Tab to have Visual Studio finish typing it for you. 58 00:03:21,930 --> 00:03:25,370 As I keep typing, I get to where I want to write a string literal. 59 00:03:25,370 --> 00:03:27,170 Notice when I type the first double quote, 60 00:03:27,170 --> 00:03:29,380 it automatically adds the ending double quote. 61 00:03:29,380 --> 00:03:31,150 I can keep typing my string. 62 00:03:34,241 --> 00:03:36,617 When I get to the end of the string, I can hit Tab, and 63 00:03:36,617 --> 00:03:39,820 it moves the cursor to the end of the line, so I can type the semicolon. 64 00:03:40,880 --> 00:03:43,810 I'll show some more of these auto complete features while I write another 65 00:03:43,810 --> 00:03:44,350 method here. 66 00:03:46,980 --> 00:03:51,190 I'll type S, T, A, Tab, 67 00:03:51,190 --> 00:03:55,080 Space, S, T, Tab, the name of the method. 68 00:03:57,723 --> 00:03:59,520 And open parenthesis. 69 00:03:59,520 --> 00:04:01,950 See the closing parenthesis was added automatically? 70 00:04:03,076 --> 00:04:09,510 S, T, Tab, and then a variable name, and Tab again to get to the end of the line. 71 00:04:09,510 --> 00:04:12,300 Return, and then an open curly brace. 72 00:04:12,300 --> 00:04:15,670 See the closing curly brace was automatically added? 73 00:04:15,670 --> 00:04:19,900 Hit Return again and the second curly brace is moved down two lines, and 74 00:04:19,900 --> 00:04:22,080 the cursor is indented. 75 00:04:22,080 --> 00:04:24,890 As you can see, typing in Visual Studio's 76 00:04:24,890 --> 00:04:29,830 text editor is very different than typing in a regular word processing program. 77 00:04:29,830 --> 00:04:34,649 It uses its knowledge of the symbols in your program, conventions used in C#, 78 00:04:34,649 --> 00:04:38,490 and the C# syntax and grammar to help you speed up your coding. 79 00:04:38,490 --> 00:04:41,530 For some coders, this may take a bit to get used to. 80 00:04:41,530 --> 00:04:45,630 After a while, it become second nature and you don't even think a lot about it. 81 00:04:45,630 --> 00:04:48,916 This allows you to spend your time thinking about the problem you're trying 82 00:04:48,916 --> 00:04:52,990 to solve and less about things like spelling syntax and what things are named. 83 00:04:52,990 --> 00:04:55,530 Another way Visual Studio tries to help you 84 00:04:55,530 --> 00:04:58,850 while typing is a feature called IntelliSense. 85 00:04:58,850 --> 00:05:03,460 IntelliSense helps you when you type a dot at the end of a valid expression. 86 00:05:03,460 --> 00:05:07,610 It determines what the type of the expression to the left of the dot is and 87 00:05:07,610 --> 00:05:09,870 then shows you a list of methods, properties and 88 00:05:09,870 --> 00:05:13,010 fields that you can call from the scope you are in. 89 00:05:13,010 --> 00:05:14,210 As you start typing, 90 00:05:14,210 --> 00:05:17,620 it highlights the symbol that you are most likely looking for. 91 00:05:17,620 --> 00:05:21,690 You can also use the up and down arrow keys to select the name. 92 00:05:21,690 --> 00:05:25,810 When you hit Tab, period, Space or any other character that makes sense in that 93 00:05:25,810 --> 00:05:28,830 context, it types the rest of the name for you. 94 00:05:28,830 --> 00:05:30,990 If you don't want it to type what is selected, 95 00:05:30,990 --> 00:05:33,270 just hit the Escape key on your keyboard. 96 00:05:33,270 --> 00:05:36,740 There are lots of other ways Visual Studio helps with typing code 97 00:05:36,740 --> 00:05:39,660 including the use of snippets and code generators 98 00:05:39,660 --> 00:05:43,020 which are more advanced than we need to cover here in this workshop. 99 00:05:43,020 --> 00:05:45,920 And of course, if you don't like some of these code typing features, 100 00:05:45,920 --> 00:05:47,460 you can always turn them off. 101 00:05:47,460 --> 00:05:50,020 However, I encourage you to experiment with them for 102 00:05:50,020 --> 00:05:51,630 a while before you make that decision.