1 00:00:00,330 --> 00:00:04,630 You may have noticed that hovering over a variable while execution is paused, 2 00:00:04,630 --> 00:00:07,340 shows us the value contained in the variable. 3 00:00:07,340 --> 00:00:08,520 Pretty nifty? 4 00:00:08,520 --> 00:00:11,760 There are other ways to see the state of the program while debugging. 5 00:00:11,760 --> 00:00:15,670 The locals window is another window that's available in debugging mode. 6 00:00:15,670 --> 00:00:18,790 This window provides details about variables declared 7 00:00:18,790 --> 00:00:22,080 in the local scope of the current method or property. 8 00:00:22,080 --> 00:00:24,970 We can use this with the call stack window. 9 00:00:24,970 --> 00:00:29,290 So if I double click on the AddSong method here, and then open up the locals window 10 00:00:29,290 --> 00:00:35,440 again, we'll see the three variables that are defined in the AddSong method. 11 00:00:35,440 --> 00:00:38,500 We can change the values of these variables while we're in the middle 12 00:00:38,500 --> 00:00:39,710 of debugging. 13 00:00:39,710 --> 00:00:42,640 Let's go back up here where we have a break point set at the beginning of 14 00:00:42,640 --> 00:00:43,560 the switch statement. 15 00:00:45,500 --> 00:00:50,401 Now, let's restart the debugger, We'll 16 00:00:50,401 --> 00:00:54,540 enter option one here, then go back to Visual Studio. 17 00:00:54,540 --> 00:00:58,530 Here we see that the option variable contains the value one. 18 00:00:58,530 --> 00:01:01,330 Now let's say that we actually wanted this value to be two, 19 00:01:01,330 --> 00:01:04,760 we can just double click on it and change it to two right here. 20 00:01:04,760 --> 00:01:09,430 Now when we step over, we go into case two instead of one. 21 00:01:09,430 --> 00:01:13,710 The locals window is limited to variables that are within scope. 22 00:01:13,710 --> 00:01:17,590 The watch window will allow us to see the values of variables that aren't declared 23 00:01:17,590 --> 00:01:22,450 in the method, such as static variables and object fields, and properties. 24 00:01:22,450 --> 00:01:26,740 This window is empty until we add something to it that we want to watch. 25 00:01:26,740 --> 00:01:31,410 We can put anything in here we like, let's add our option variable to the watch 26 00:01:31,410 --> 00:01:36,120 window by right clicking on the variable and clicking, add watch. 27 00:01:36,120 --> 00:01:39,430 Here, we see that it appears and we can see its value. 28 00:01:39,430 --> 00:01:43,580 Like the locals window, we can also double click in the value cell and 29 00:01:43,580 --> 00:01:45,130 change the value while we're debugging. 30 00:01:47,010 --> 00:01:49,800 We can also evaluate expressions in here. 31 00:01:49,800 --> 00:01:54,300 Let's create a new instance of song in the watch window right here. 32 00:01:54,300 --> 00:01:57,455 So say, new Song, 33 00:01:57,455 --> 00:02:02,790 Artist="Set For the Fall". 34 00:02:05,876 --> 00:02:09,884 Name="Three Nails". 35 00:02:12,821 --> 00:02:17,700 I'll hide the call stack window to give us more room. 36 00:02:17,700 --> 00:02:22,170 One of the things you may notice is that we now have this expander icon here. 37 00:02:22,170 --> 00:02:27,100 Expanding this will show us the fields and properties that this object contains. 38 00:02:27,100 --> 00:02:31,410 We can in turn add them to the watch window by right-clicking on them and 39 00:02:31,410 --> 00:02:32,920 then clicking, add watch. 40 00:02:37,858 --> 00:02:41,900 If we want to focus in on a single variable or expression quickly, 41 00:02:41,900 --> 00:02:44,520 we can use the quick watch window. 42 00:02:44,520 --> 00:02:47,440 We'll use the option variable again to demonstrate. 43 00:02:47,440 --> 00:02:50,410 Just right click on the option variable and click, quick watch. 44 00:02:51,690 --> 00:02:53,470 Here, we can quickly inspect a variable or 45 00:02:53,470 --> 00:02:56,380 expression without having to add it to the watch window first. 46 00:03:00,054 --> 00:03:04,542 The watch window is great when executing expressions and seeing the result, but 47 00:03:04,542 --> 00:03:08,832 we can't do anything in there to affect the actual execution of the program. 48 00:03:08,832 --> 00:03:11,214 The immediate window on the other hand, 49 00:03:11,214 --> 00:03:15,360 allows us to run any code we want in the context of our running program. 50 00:03:15,360 --> 00:03:20,282 From here, we can create variables, evaluate expressions, call methods and 51 00:03:20,282 --> 00:03:23,580 print variable values while the debugging. 52 00:03:23,580 --> 00:03:26,500 I'll demonstrate this using the immediate window, 53 00:03:26,500 --> 00:03:30,700 by creating a new song object that we've not added to the application yet. 54 00:03:30,700 --> 00:03:33,090 And then I'll add it to the list of songs. 55 00:03:33,090 --> 00:03:38,343 So I'll say, songs.Add, and notice that we're getting Intellicence here. 56 00:03:38,343 --> 00:03:40,460 New song. 57 00:03:40,460 --> 00:03:44,767 And say, Artist=, 58 00:03:44,767 --> 00:03:48,120 just say "A". 59 00:03:48,120 --> 00:03:52,655 And Name="B". 60 00:03:52,655 --> 00:03:56,380 You always need to remember to put a semi-colon here. 61 00:03:56,380 --> 00:04:00,550 I'm setting the name property, so we've hit this break point. 62 00:04:00,550 --> 00:04:04,670 As you can see, we still hit break points when we're using the immediate window. 63 00:04:04,670 --> 00:04:07,290 Now, if I hit continue to keep running the debugger. 64 00:04:09,197 --> 00:04:13,314 We can see that our new song was printed in the song list. 65 00:04:13,314 --> 00:04:16,944 The immediate window can really come in handy when trying something out. 66 00:04:16,944 --> 00:04:20,554 Or testing expressions and working with object instances and methods.