>> Hey, friends we're continuing our.NET Core 101 video series.
In our C# series,
we talked a little bit about basic debugging.
You showed me how to do a break point,
but it was pretty basic and you said there's a lot more there.
>> Definitely.
>> Now, when I go over into Visual Studio,
and this is our bank application the same one that we use before,
I have been habitually saying start without debugging,
I just hit "Control" and "F5", it's a hotkey,
and I run my application and it works great,
and you can see right there
Ctrl+F5 is the hotkey and start without debugging.
Let's start debugging, is what most people do and
there's a button for it right there.
>> All right. So let's dive in by setting a break point first.
>> Okay.
>> You can do that by clicking one are the margins on the left.
>> Okay. So not that margin,
but when the mouse flips over to the right.
>> Yeah.
>> I can set the break point.
>> I can get a red dot.
So looks like a stop sign.
>> Oh, and if I hover over the red dot,
it's telling me exactly the line that it's going to break on.
Okay. That's a pause, isn't it?
>> Yeah. So why don't we go ahead and run that and just
see what happens to
all of our windows that pop up when our break point is reached.
>> Yeah, this is like it's changed,
like the Visual Studio that you're used to,
it opens up additional toolboxes and windows
all trying to be helpful to let
you know what's going on with your system here.
>> Right. It's giving you a lot of feedback.
So diagnostic tools can show you like memory usage and whatnot,
you have a different events over in the pane right below it.
What I always go to first of course is the autos,
locals, and watch windows.
So these actually provide a search box.
So you can search exactly what
values are currently in your variables.
>> Oh, I didn't even realize that like I know that this is a tree,
but if I can go and search for balance and hit Enter look at that.
>> Yeah.
>> So I'm actually searching the state of all of my objects.
So I know that I'm paused right here.
Account I just made one,
and I just wanted to know what the balance was it
took me right there, and it's like a little tree.
It shows me my account and the things about my account and look,
I can even go deeper.
Remember, in our C# video,
we talked about how there's transactions.
Third, look I can see my initial balance for my account.
>> Yeah.
>> At that moment.
>> That is one of the reasons that the search is really important
because a lot of things can nest really
deeply inside of your whole variable's scopes.
So being able to search and you can
even search different search depths.
So right now it's set default,
set to three, but we can go up to 10.
So if you have very nested types and properties and everything,
you can still find those.
>> Cool. I noticed that right now my bank account
only has the one transaction,
and I've been taking money in and out.
But I'm worried that people are taking too much,
and I was hitting F10,
we learned about that a little bit, stepping over,
and I was noticing as I add
my transactions, they were getting added right there,
but I don't want to keep going F10 , F10,
F10 like I had a loop earlier where I had 100 and something,
and it was getting really tedious.
>> Right.
>> I really want to break point,
but I want a break point only
when people are taking a lot of money.
>> Right. So you when a conditional break point.
>> Yes, I think that sounds right.
>> So we have those. So if you went to
go maybe start another break point,
actually you want to add a few withdrawals that are less that a-
>> Yeah, it's a good idea. So let's do this.
>> -certain amount.
>> Let's make a bunch more withdraws.
So I'm going to go and hit the "Stop" button,
and that's a great point.
Let's go and add a bunch of little withdrawals,
and we'll say five dollars,
and five dollars, and seven dollars,
and eight dollars, and we're going to
buy if we like coffee and Diet Coke.
>> Sounds good.
>> Diet code and Diet Coke.
>> If you want to slim your code down real quick, good diet.
>> Okay. So I've got a bunch of stuff here,
but then in the middle of my loop,
I'll take out $120.
So that's the one I want to catch now.
I know I can set a break point there,
but I want to find out what's happening maybe deeper.
So I'm going to right-click and say go to definition,
and this is the code that we wrote in our other videos,
where we make a withdrawal.
I could hit a break point here.
Hit F5, which is for start debugging,
and then using that, there you go.
So there's the first one.
>> Right. So the amount is 50.
>> Okay.
>> But that is not the value that you are looking for.
>> Now, it's five continue,
and now it's five, and this is really tedious. This was no fun.
>> Yeah, you don't want to hit that every time.
>> Okay. So what did you say I can do?
>> So a conditional break point is something you can modify.
So if you go and hover over
your break point and hit back "Settings" button,
it will go to Gear icon.
>> Or at the gear too. Oh, hey.
Okay. Bank account line 50 conditions.
>> Yeah. So you don't have any right now.
If you go ahead and check that,
you'll be able to set a condition for a
certain variable being
a certain amount that you want to watch out for.
>> We talked about if statements,
and in fact there's an if statement.
So I bet you I can go and say amount,
hey, look I got the IntelliSense.
>> Oh, Wow.
>> I'm writing code, but I'm not because it's
a statement inside of Visual Studio.
So what? Over 100 bucks maybe.
>> Yeah. That sounds good.
>> Okay.
>> So it's very much like anything you
would write in a regular if condition.
>> Okay. Then look my little dot changed,
and now it says, when amount over 100 is neutral.
So if we did this right,
even though we are making six withdrawals,
only the break point will happen once.
>> Right.
>> is that right?
>> Only the one that's over 100.
>> Only the one over 100. So let's go and see
if that worked. Okay.
>> Amount is 120.
>> Yes. Look at that and let's make sure,
look, we are already four transactions in.
>> Right.
>> One of the things that is worth reminding
ourselves of is how fast that was,
like computers run fast.
So even though we added
four transaction that all happened in like a millisecond.
So now, I can hover over that amount and see it,
and then I can hit F5 for continue,
and then that was it, it ran, the whole thing ran.
>> Right.
>> That is pretty cool. It's also worth pointing out,
when I'm debugging, I've been noticing these little things.
I'm just moving my mouse and look,
it popped up a little tip.
>> Yeah. You can even pin that tip,
if you see the little pin on the side.
There you go. So as you step through it,
that amount will continue to update.
>> I can leave notes.
>> Wow.
>> I can leave notes to myself.
You said that it'll update?
>> Yeah. So keep on hitting F5,
and you can see.
>> Let's go. Hang on. I was hitting F10,
I was going to step over, step over.
I want to go back inside there.
I'm not done yet. I want to go and see my tool-tip.
So I don't want to step over,
I want to step into.
See this says step over.
Why don't we go inside?
See, that's F10, I just stepped over to the next line.
Why don't we go F11.
Now, we're back in there,
and look there it is. There's our tool-tip.
>> Yeah.
>> F10, F10 those are going line by line, and then F11,
you look up here there's step over
to the next thing and step into,
and then you said F5, which is continue.
>> That's all. Exit the program.
>> Now we're done.
>> Cool.
>> Very cool. That is the basics
of debugging our bank application.
>> Right. So that's debugging.
Why don't we talk a little bit about debugging versus release.
Because we've been saying debugging a lot,
but we do actually have this dropdown up there at the top.
So we can also select release.
So the main differences between these two is debugging
has a bit more context on your code when you execute it,
and when you release it,
release is actually trimmed down how the EXE is created.
So you want to use release when you're ready
to ship your app to its users,
and you want to use debug when you're currently in development.
>> Right. One way to think about it is that debug knows
about your lines of code and it makes it easy to debug,
and release makes it really easy for.NET
and C# to optimize it to make it fast for release.
So, who is your audience?
Is it you for debugging?
Or is it the world who is going to get your great application?
Fantastic. Now, speaking of our great application,
right now we just have one project and
the one that we've been working on all this time,
I think it's time to maybe refactor and move
it around and learn more about projects and solutions.
>> Sounds good.
>> All right. Stick with us.