In this section, you will learn how to debug problems at design time, trace problems at runtime, and use types such as Debug
, Trace
, Process
, and Stopwatch
that are in the System.Diagnostics
namespace.
In Visual Studio, press Ctrl + Shift + N or navigate to File | New | Project….
In the New Project dialog, from the Installed Templates list, select Visual C#. In the list at the center, select Console Application, type the name Ch05_Debugging, change the location to C:\Code
, type the solution name Chapter05, and then click on OK.
Modify the template code to look like this:
using static System.Console; namespace Ch05_Debugging { class Program { static double Add(double a, double b) { return a * b; // deliberate bug! } static void Main(string[] args) { double a = 4.5; // or use var double b = 2.5; double answer = Add(a, b); WriteLine($"{a...