Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Visual Studio 2013 and .NET 4.5 Expert Cookbook

You're reading from   Visual Studio 2013 and .NET 4.5 Expert Cookbook Over 30 recipes to successfully mix the powerful capabilities of Visual Studio 2013 with .NET 4.5

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781849689724
Length 308 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Abhishek Sur Abhishek Sur
Author Profile Icon Abhishek Sur
Abhishek Sur
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. A Guide to Debugging with Visual Studio FREE CHAPTER 2. Enhancements to WCF 4.5 3. Building a Touch-sensitive Device Application Using Windows Phone 8 4. Working with Team Foundation Server 5. Testing Applications Using Visual Studio 2013 6. Extending the Visual Studio IDE 7. Understanding Cloud Computing with Windows Azure Index

Introduction

Being one of the best IDEs available, it may often seem that our knowledge about Visual Studio falls short when some special circumstances appear. Visual Studio provides hundreds of tools inside it and also some tools as extensions to help programmers develop software in the best possible ways. It incorporates features such as refactoring, code analysis, clone code finder, and so on to let a developer write better code and have the best experience while inside the IDE. Visual Studio has been so popular that it is not constrained to just software development; some people use it to edit documents and images, or even to publish content. It is so user friendly and easy to use that anyone can work on it at a basic level.

Debugging is the most important part of any application development process. People like to start debugging a program while developing code. Debugging is a process that lets you have a quick look at the current state of a program by walking through your code step by step and letting you identify what exactly is happening while the program is running. Developers expect an IDE to give them as much information as possible during a certain state of the program. Visual Studio has taken every step to improve the debugging experience of the IDE and make small tools to let developers find better ways to quickly find the possible problems in code (if any).

After opening the IDE, it is often the case that people start typing some code. But, it is unlikely that developers will always finish writing the code before they start debugging. After some part of the development is done, they tend to start debugging it to have a better understanding of the logic and functionalities. Some people start debugging even before they have written a single line of code. So debugging is not just identifying bugs, it is determining the merits and demerits of the code as well. Debugging inside Visual Studio is perhaps the best selling point of the IDE.

Visual Studio separates the environment layout completely while debugging. After writing your code, when you press F5 on the keyboard or go to Debug | Start Debugging, Visual Studio adjusts the whole layout of the window and creates an environment that is best suited for debugging; for instance, when you are in the debug mode, generally the Solution Explorer, Toolbox, the Properties window, and so on get hidden. Instead, windows such as IntelliTrace, Autos, Locals, Watch, and Call Stack automatically open inside the IDE and get docked/adjusted to the layout inside the IDE. The IDE is smart enough to store the layout information of all the opened windows inside it when the debugging session is closed by the user for a particular project. Therefore, when you start debugging again, the IDE provides you an environment that is exactly adjusted to the left-hand side when the previous debug session is closed.

In this chapter, we will try to demonstrate some of the important debugging tools available in the IDE. Let's start with a simple class that consists of a few properties and methods:

public class TestClass
{
  public int Start { get; set; }
  public int End { get; set; }

  public TestClass(int start, int end)
  {
    this.Start = start;
    this.End = end;
  }
  public int GetSum(int start, int end)
  {
    var sum = 0;
    for (var i = start; i <= end; i++)
      sum += i;
    return sum;
  }

  public string GetMessage()
  {
    var sum = this.GetSum(this.Start, this.End);
    return string.Format("Sum of all numbers between {0} and {1}  is {2}", this.Start, this.End, sum);
  }
  public void PrintMessage()
    {
      var message = this.GetMessage();
      Console.WriteLine(message);
      Console.ReadKey(true); 
    }

  }
  class Program
  {
    static void Main(string[] args)
    {
      var tclass = new TestClass(20, 30);
      tclass.PrintMessage();
    }
  }
}

The dummy code that we are using here has a TestClass, which takes two arguments and stores data in the data members Start and End. GetSum is a method that sums up all the integers between Start and End. The GetMessage returns a message after calling Sum with Start and End, and finally PrintMessage prints the message on the console.

The program creates an object of TestClass and calls PrintMessage with 20, 30. If you run the program, it shows 275 on the console.

You have been reading a chapter from
Visual Studio 2013 and .NET 4.5 Expert Cookbook
Published in: Sep 2014
Publisher:
ISBN-13: 9781849689724
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime