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. You can debug your variables in the Visual Studio integrated development environment.

This C# tutorial provides steps for debugging variables. It requires Visual Studio.
First here we look at a short program written in the C# language that has several local variables in it. To look inside your locals, you need to set a breakpoint somewhere in the block of C# code you have. For the example, I will use this simple program.
Program that uses local variables [C#]
using System;
class Program
{
static void Main()
{
// A.
// An integer is local.
int cat = 1;
// B.
// A string is local.
string dog = "cute";
// C.
// An array is local.
bool[] b = new bool[]
{
true,
false,
true,
true
};
}
}Here in the tutorial we will 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. 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.

When you set the breakpoint red circle on your code, the debugger will open only if that point is hit. This makes it possible to use breakpoints to alert you if something unexpected happens.
Here we note how 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. See the screenshot at the top of this article for what this will look like. Next, open the Locals window. Like many windows in Visual Studio 2008, you can open the Locals pane in more than one way. Go to Debug -> Windows -> Locals.
Here we look at some features in the Visual Studio integrated development environment related to local variable debugging. In Visual Studio 2008, you can see Locals' values. You can browse hierarchies of the locals' internals. You can visualize data in a few ways too.

Name
The name of your variable.
Value
The data stored in your variable.
Type
The data type of your variable, such as int, string, bool[].
Text Visualizer
Allows you to see the plain text value in the variable.
XML Visualizer
For XML files. Probably uses the XML engine from Internet Explorer.
HTML Visualizer
Use to view the data in Internet Explorer as HTML.
Expression
This is on the Visualizer windows. Shows the variable name.
Let's look at step options in the Visual Studio debugger. 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.

Step Into (F11)
"Step Into executes only the call itself,
then halts at the first line of code inside the function." (MSDN)
Use Step Into to go inside your method and stop immediately inside it.
Step Over
Moves to the next step in your code also, but doesn't break inside any methods.
Step Out
Ignores the rest of the current method and goes to the calling method.
Step example in this tutorial. 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.
Here we examine the array type in the C# programming language as it appears during execution in the Visual Studio debugger. The screenshot shows what local arrays will look like. Each element in the array is referenced by an index. Look inside an array by clicking on the + box.
- b - name of the array
[0] true - first value in array
[1] false - second value in array
[2] true - third
[3] true - fourth
Here we note that the Visual Studio 2008 debugger is very thorough and effective for most problems. It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.
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. The debugger causes significant performance overhead. In my experience it takes close to twice the time to execute Debug programs.
There are three ways to disable debugging. In your ASP.NET website, open Web.config and change the compilation tag's debug attribute to false. In Windows Forms or Console applications, go to Project -> MyApplication Properties... Then change the Configure dropdown to Release. The third way is to change the toolbar dropdown when it is available.
Other methods are available to you for debugging complex or simple programs written in the C# programming language. If you are using a console program, the Console.WriteLine method (or Console.Write) are very useful. This doesn't involve the Visual Studio debugging environment so can be used when testing release builds and for accurate performance testing.
Console.WriteLine
The .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. 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. You can find more details on these methods.
Debug.Write Method
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 very cumbersome. With the debugger, we eliminate lots of manual work. In the C language, programmers use 'printf' statements, which are like Console.Write in the C# language. However, using Locals in the debugger is easier for many developers.
Visual Studio Tips