Debug Multi-line C# Statements in VS 2015

There may be few situations where you need to debug and inspect values of all variables in a multi-line statement. In VS 2013 and 2015, we can easily inspect variables and method return values involved in a multi-line statement like 
 
int d = a + b + c + addRandomNbr();  
 
Let's create a sample C# console application in VS 2015 and add the below piece of multi-line code: 
  1. static void Main(string[] args)  
  2.        {  
  3.            int a = 0, b=10, c=20;  
  4.            int d = a + b + c + addRandomNbr();  
  5.            Console.WriteLine(d);  
  6.            Console.ReadKey();  
  7.        }  
  8.        static int addRandomNbr()  
  9.        {  
  10.            return new Random().Next();  
  11.        }  
Let's keep the breakpoint on line 04 and hit F10, We can see values of all variables in Autos window:

 

Let's press F10, Now we can inspect values of all variables and return value of method addRandomNbr() as well. 



By using Autos window, we can easily debug and inspect multi-line statements.
Ebook Download
View all
Learn
View all