Print statements are often the first step in debugging an application in C#, and it's good to be familiar with them in case you want to discover the value of a specific variable quickly. Learn the power of print statements in this video.
- [Kathryn] A print statement allows you to send output … to the standard output unit of your computer, … usually your console or terminal. … You've probably used print statements all along, … but here we'll put them into context with debugging. … Here we have Visual Studio Code open, … and in C#, a print statement looks like this. … We have Console.WriteLine, … with whatever we want to print out in the parentheses. … We also add using System at the top in order to get access … to the console so we can print data to it. … Let's go ahead and run this code, … and this is just a hello world application. … You've probably done this dozens of times, … but with debugging it can get a little bit more complicated. … With this statement, … we're just printing out a hardcoded value, … which isn't super useful. … In debugging, sometimes we'll want … to print the value of a given variable … to understand more fully how our program is working. … So let's go ahead … and add an int a, which we'll give the value 10, …
- Debugging defined
- Working with breakpoints
- Inspecting values of variables
- Defensive programming
- Common C# errors
- Debugging challenges