Debugging Applications


A key highlight of an IDE is that apart from project file management and building solutions, you can debug applications right from within the environment. Debugging applications isn't really a luxury but a requirement when the functionality provided by the application increases and team development starts. Whether you are developing console or Windows applications, Web applications, or Web services, Visual Studio .NET provides extensive debugging capabilities through an integrated debugger. To take a quick look, you can develop a simple application program that could use some debugging. The following listing is of another popular getting-started application ”Get the Factorial of a Number.

 
 using System; namespace hks {    class Factorial    {       static int getFactorial(int number)       {          if (number ==1)             return number;          else          {             int fn = number*getFactorial(number-1);             return fn;          }       }       [STAThread]       static void Main(string[] args)       {          Console.WriteLine(getFactorial(5));       }    } } 

The key to start debugging an application is to first set up some breakpoints where you would like to watch the program as it executes, and then use Debug, Start to start the application. In this scenario, a breakpoint is at line 9, which contains the return number; statement (see Figure 5.35).

Figure 5.35. Debugging applications using Visual Studio .NET.

Visual Studio automatically shows the variables ' values within scope. If you want to explicitly watch a variable, you can highlight the variable name while debugging and select the option to Add Watch. A key to successful debugging applications is to know shortcuts to move forward:

  • F5 : Continue, run the program

  • F11 : Step into

  • F10 : Step over

  • Shift+F5 : Stop debugging

  • Shift+F11 : Step out

  • Ctrl+B : Set up a new breakpoint

  • Ctrl+Alt+Q : Perform a quick watch on a variable or expression

What you have learned in this section is a very small precursor to the debugging capabilities that are provided by the Visual Studio .NET environment. Visual Studio .NET supports debugging across programming languages, remote debugging across machines, ASP.NET “based Web applications and services, debugging SQL Server 7.0/2000 stored procedures, and so on.



Microsoft.Net Kick Start
Microsoft .NET Kick Start
ISBN: 0672325748
EAN: 2147483647
Year: 2003
Pages: 195
Authors: Hitesh Seth

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net