 Hi, in this video, we will be seeing like how to debug a C sharp code in a sharp develop ID. So let us see like what outcomes have been listed for today's videos. The learning outcomes associated with this session of video would be to make sure that once a student goes through this video or any participant goes through this video, he or she should be able to debug a sharp develop code using a sharp develop ID. So when we talk about a sharp develop code, it could be like a C sharp, it could be VP.NET or it could be any.NET supported language. But for this video, when we are using sharp develop ID debug layout, we will be more focused on the concept specially called as step into, step over and step out. At the same time, while going through step into step over and step out process, we will be even be interested in exploring the variables and debug perspective as well. So why do we need to explore variables in debug perspective? Because most of the times when we do some kind of like mathematical arithmetic or some kind of processing of a data, we always store them in a variables or it could be even an array of variables as well. So to make sure the variables have been assigned proper values is one of the very crucial part of a debugging process. So let us do an hands on. So what we'll be doing is we'll be switching to sharp develop and we'll proceed ahead from there on. So let me switch to sharp develop. My ID is a blank here. I'll create a project and in this project and we all know that before we create a project, we need to create a solution. So let me create a solution first and we will make it as a console application just to make things simple and we'll call it as linear search. Since we will be using linear search as a use case to debug a program. So the name of my project is linear search and rest all I have kept it as default and I will click on create button. So it will create the solution and under that the project will be created. It will also add a default file program.cs. So just to have a clean view, I'm deleting the auto generated comments and I'll increase the font. Okay, so looks font is visible here. Okay, so no, no, let us write the program. And once we write the program, then we'll talk about a concept called as a breakpoint. And what are breakpoints and what's the role of breakpoints in debugging process. So I need to search an integer array. So I'll take a key element. So let us say I'll decide a value for example, let us make the key value zero. And then I'll take an integer array. So I'll take array of integers. And let me initialize that here itself. So to declare an array, we'll use this array center and initialize it with a few elements in it. For example, I'll keep two, three, four, seven and zero. So in my case, if you're talking about the use case of linear search, zero is present in that. So I need to let's let's write a program like for example, this program will output true Boolean true, if the key element is found in the array of integers. If the element is not found, it will print false. So what we'll do is we'll declare one more variable that would be Boolean. Boolean is element present. So by default, I'll say element is not present false, I kept it as false. Then in order to search to an entire array, we'll use a for each loop here in dot net. So here I'll say for each int temporary in array of integers, if temporary values equal to our key element, if it is equal to our key element, then what we'll do is we'll set is element to true and will break the loop. So once I break a loop, so when I'm out of this loop structure here, so let me write this code properly. Okay, so once I'm out of this, I'll be checking the value of a key. Sorry, it can't be a key as per our code, it should be is element. So I'll check the value of this is element. See, sometimes this auto completion might. So in such a case is better, it's always you cut and paste it directly. So this sometimes it becomes issue is sharp enough because it's auto completion feature is not that up to the mark when we compare it with Visual Studio. So if is element present, I'll put a console dot right line. I need to print the element, I'll directly print is element. Okay, let us do one thing we this was not what we wanted. Let me let us do let us call as element form. And if it isn't, so if is element Boolean variable remains false, even after iterating to an entire array, it's an indication that element is not present. So in that case, we'll do a console dot right line, and we'll print a message element not form. Fine, so let us first execute this code and let us select. Okay, now, if we run this program, it would be quite easy for me to say whether the program is working or not. But what I'll do is, we will try to debug rather than executing the program. So here I would be interested to know like what is the state of a program in a middle of execution or at the end of execution. Remember, in order to stop the program during it's an execution and explore the values of various variables at that moment and explore how the control flow is there, like changing the value of that variable during any execution, it can it can be facilitated by a special feature of many of the ideas. Rather than calling many of ideas, almost all language runtime and all of language runtime specific ideas, they do support the feature. This feature is called an inserting breakpoint. The name of breakpoint itself is quite self excellent. So when I say I am inserting a breakpoint, so if I want to insert a breakpoint where so what I'll do is here my element is searching for all. So what I'll do at this moment of break here at this line, the selected line which I have selected, I'll put a breakpoint. So what happens is, whenever the line of execution is at this instruction at line number 16, your execution just pauses and you debugger what it does, it shows you all the values of variables at this point. And it also lets you change the values of these variables as well. We call it as watch window. So in a watch window, we can list out the names of variables whose values we are interested in exploring at that mid stop execution where I inserted breakpoint. So here now I want to insert a breakpoint at line number 16. So what I would be doing is select the line or just put your cursor there and click on debug here. So I clicked on debug menu and under debug menu, you will find a submenu called as toggle breakpoint. So click on that. Yes, the breakpoint is inserted. So this is what we call it as breakpoint. So now the moment I inserted a breakpoint, now instead of running the program, we'll click on debug the program. And now you can just, I would just ask you all to follow the process from now on little bit carefully because our windows would be changing, a lot of new windows would be opening here. So we have set a breakpoint here. Now we'll go to debug and I'll run this program by clicking Fi. Now I'll not run without debugger. So before we debug this program, let us build the application just to ascertain that we don't have any errors in this. So I'm clicking on build solution. Okay, so we have some errors like maybe we might have missed something for each temporary, I think maybe it's in, sorry, I missed the syntax here. So let me rebuild once again. Okay, so build finished successfully. So it's not colon like I was just writing a Java based syntax, but it's an in it's a for its syntax. Okay, so the program has built fine. It means that I don't have errors in this code. So now I can initiate a debugging process. Now I'll click on run. Remember, I'm not clicking on run with a debugger. I want to debug this. So I'll click on run. And I have already a breakpoint inserted at line number 16 to stop my execution of program at that point. So I'll clicking on run. Now you can see that like the whole windows have just changed. And you can see that here I have a new window called as call stack window, the other the project window, the classes, the output window remain same. But you can see that here there's a new window with the where I'm moving my mouse, the cursor where I'm moving this window was newly created here. So under this you can see I have a call stack. So it gives me the name of my program. And if there had been a branching and all further things in this, it would have shown you some tree like structure where you can expand every point there. And here I have a watch window. And here I have console. So now what I am more interested in. So my execution stopped at point at this line number 16, you can see this arrow indicating that the my current point at which my execution stopped. So from here onwards, I want my debugger to continue execution. And before a value of well, so I'll click on add watch, and I'll list out the name of this value 10. So the temp value is this, I'll add one more variable to my watch, and I'll call it as key. Okay, and one more value. And I'll call this as is element present. It's by default true, okay, because it was set as true. So now my execution stopped at this point, I want this execution to proceed further. Then here I have a few choices. So the few choices are step over, step into, or step out. So the meaning of step over step into step out is let us suppose the line at which I have right now my execution is pending, had that line contained a function call. And if I click on step over, what my debugger would do is debug would execute the function call, and it will move from that line on. If I say step into and had the line where I had a breakpoint been a function call step into will take my debuggers control into that inside function. So I would end up debugging even the function deeply into its level. And the moment when I'm debugging functions deep by using step into menu, at a point if I feel no, I don't have any problem with the function and I want to continue with debugging my earlier program, I would click on step out. So step out would take me my debugger's control from a function to the function which are actually called that function. So right now, quickly, what we have seen in this hands-on is we have seen that sharp develop, let us let us let us debug a C sharp code. And to debug a code what we need to do is we need to rely on a place we need to learn concept called breakpoints. And more wisely you choose a breakpoints and it's watch variables more precisely you will be able to debug the program. So the question like I have quick reflection question for you. What does a watch window let you do like to be more precise, does watch window lets you change the value of variable? What do you think like? So you can think on it and you can recall an answer. But the answer right answer here is yes, watch window specifically when we are talking about sharp develop ID, yes, it lets you say change the value of variable dynamically through the watch window. As a further reading, I would recommend you explore the ring where you have a lot of debugging features of sharp develop explained in detail. And this bibliography which I referred to make this PowerPoint. And to be more precise and to have a better knowledge of debugging feature, I would expect you to go through the Microsoft documentation which talks very detailed the processes steps to debug programs more meticulously and carefully. So this is it for this video and thank you.