Debugging.` The values of local variables change as a program executes. It is possible to see these changes. This is useful for when you want to make sure the values are correct.`Visual Studio.` You can debug your variables in the Visual Studio integrated development environment. This is a short tutorial. In it, we deal with local variables.`A program.` First here we look at a short program that has several local variables in it. To look inside your locals, you need to set a breakpoint somewhere in the code. `First: `Please start up your version of Visual Studio and create a new C# console application.`Debugging breakpoint.` Here we add a breakpoint near the end of the above program. On the far left of your source code tab, you will see a narrow gray strip. `Then: `Click on it in the line you want to debug. The red circle on the left is where you need to click to set the debugging breakpoint.`The red block over the code line is where the debugger will open. We must first execute the program.`450px`300px`Point hit.` When you set the breakpoint red circle on your code, the debugger will open only if that point is hit. So breakpoints can alert you if something unexpected happens.`Start debugging.` You can initialize the debugger at the same time as starting your program in Visual Studio. To do this, click on the green arrow in your Visual Studio toolbar. `The icons on your setup will look a little different depending on your preferences and OS.`The breakpoint` will be hit as the program executes. The red blocks will turn yellow and you may see different panes such as the Call Stack pane. `Next: `Open the Locals window. You can open the Locals pane in more than one way. Go to Debug -> Windows -> Locals.`Locals.` Here we look at some features in the Visual Studio IDE related to local variable debugging. You can browse hierarchies of the locals' internals. `Many of these options are advanced and not needed for most debugging purposes.`Step over.` Let's look at step options. Often when debugging, you want to advance one step. Clicking the green arrow in the toolbar to Continue will take you to the next breakpoint. `Using these options takes practice. It is hard to learn them at the same time you are learning an entire language.`Step example.` In our example, we want to use Step Over. This will enable us to see the values of all of the variables. The final variable is assigned at the end of the method.`Arrays.` Here we examine the array type as it appears during execution in the Visual Studio debugger. This is an effective way to monitor the values of elements in an array during runtime. `The screenshot shows the local arrays. Each element in the array is referenced by an index.`Look inside an array by clicking on the + box. You can browse all elements.`Options.` The debugger has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints. `With break points, we can write messages to the console, or keep counts of how many times they are hit.`Activation Record `activation-record`Disable debugger.` Before you ever deploy your web site or Windows Forms application, disable debugging. This will eliminate the features in this article but you can re-enable it later. `Method 1: `In your ASP.NET website, open Web.config and change the compilation tag's debug attribute to false.`Method 2: `In Windows applications, go to Project -> MyApplication Properties. Then change the Configure dropdown to Release.`Method 3: `The third way is to change the toolbar dropdown when it is available.`Overhead.` The debugger causes significant performance overhead. In my experience it takes close to twice the time to execute Debug programs. `This depends on the program. More complex, algorithmic programs tend to become still slower.`Benchmark: `For benchmarking, please run outside of the debugger. For the best benchmarks, do not involve Visual Studio at all.`Benchmark `benchmark`Edit value.` We can use the "Edit Value" feature to change the value of a variable in a program as it runs. Try this. On the second if-statement, add a breakpoint. `Then: `When the breakpoint is hit, right click on its value in the Locals window. And change its value to 3.`Result: `The value "true" will be printed twice. We edited the value to be 2 and then 3.`Console.` Other methods are available to you for debugging complex or simple programs. If you are using a console program, the Console.WriteLine method (or Console.Write) are useful. `This doesn't involve the VS debugging environment. So they can be used when testing release builds and for performance testing.`Console.WriteLine `console`Debug methods.` The .NET Framework provides methods in the Debug class that can be used to hard-code debugging facilities. Some methods that you can use are Debug.Write and Debug.Assert. `The benefit to these methods over the Console methods is that they are removed in Release builds of your application.`Debug.Write `debug-write`A summary.` We looked inside the variables in methods using the Visual Studio debugger. Local variables are part of every program, and writing them out with Console.Write is cumbersome.`With the debugger,` we eliminate lots of manual work. In the C language, programmers use "printf" statements, which are like Console.Write. But using Locals in the debugger is easier.`As time passes,` I update this tutorial. I created it originally for Visual Studio 2008. But this current version targets Visual Studio 2013.

RDGKqGGDDDQDbDJDAG{GRD%R{qGRRD{A.GRRD{An Dzeger is local.GRRqDicatDy1;qGGRRD{B.GRRD{A DP is local.GRRqDP dogDyKcuteK;qGGRRD{C.GRRD{An DU is local.GRRqbool[] bDyDqbool[]GRR{GRRRtrue,GRRRfalse,GRRRtrue,GRRRtrueGRR};GR}G}qPropertiesDpdebugger: Visual StudioqGGqName:qGThe name of your variable.GGqDX:qGThe data storedDpyour variable.GGqType:qGThe data type of your variable, such as Dz, DP, bool[].GGqText Visualizer:qGAllows youDjsee the plain text DhDpthe variable.GGqXML Visualizer:qGDsXML files. You can visualize XML data with this function.GGqHTML Visualizer:qGUseDjview the dataDpInternet Explorer as HTML.GGqExpression:qGThis is on the Visualizer windows. Shows the variable name.qStep options: Visual StudioqGGqStep Into, F11:qGUse Step IntoDjgo inside your mDgDVstop immediately inside it.GGqStep Over:qGThis also movesDjthe next stepDpyour code.GIt doesn't, however, break inside any mDgs.GGqStep Out:qGIgnores the rest of the current mDgDVgoesDjthe calling mDg.qDS D8sqGG- bqRRR - name of the DUGRq[0] trueqR - first DhDpDUGRq[1] falseqR- second DhDpDUGRq[2] trueqR - thirdGRq[3] trueqR - fourthqDA DwEdit DX demonstration: C#qGGDDDQDbDJDAG{GRD%R{GRRDiDhDy2;GRRDmDhDx2)GRR{GRRRD'qtrueq);GRR}GRRDmDhDx3)GRR{GRRRD'qtrueq);GRR}GR}G}GGqGGtrueGtrueq

!_local variables