Breakpoints with Objects and Files

Introduction

In the previous sections, we created all our breakpoints in one source file. As you know already, a program can use many files, some files come from the .NET Framework, some are created by Microsoft Visual Studio when you start a project, and you create the others as you judge them necessary for your project. As a result, when debugging, you can consider files that are linked at one time or another. The process of debugging is primarily the same. You just have to keep in mind that you are dealing with many classes and probably different files.

Breakpoints and Classes

Practical LearningPractical Learning: Debugging With a Class

  1. Start Microsoft Visual Studio
  2. Create a new C# Console App named StellarWaterPoint12
  3. To create a folder, in the Solution Explorer, right-click StellarWaterPoint12 -> Add -> New Folder
  4. Type Models and press Enter
  5. To create a new class, in the Solution Explorer, right-click Models -> Add -> Class...
  6. Change the Name to Customer
  7. Click Add
  8. Change the class as follows:
    namespace WattsALoan02.Models
    {
        internal class Customer
        {
            public string fullName;
            public string phoneNumber;
    
            public Customer(string name = "John Doe", string phone = "000-000-0000")
            {
                fullName = name;
                phoneNumber = phone;
            }
        }
    }
  9. To create another class, in the Solution Explorer, right-click Models -> Add -> Class...
  10. Type Employee
  11. Press Enter
  12. Change the class as follows:
    namespace WattsALoan02.Models
    {
        internal class Employee
        {
            public long   employeeNumber;
            public string firstName;
            public string lastName;
            public string title;
    
            public Employee(long   emplNbr  = 0,
                            string fName    = "Unknown",
                            string lName    = " Not Specified",
                            string position = "Loan Specialist")
            {
                lastName       = lName;
                firstName      = fName;
                employeeNumber = emplNbr;
                title          = position;
            }
    
            public string GetEmployeeName()
            {
                return lastName + ", " + firstName;
            }
        }
    }
  13. To add another class to the project, in the Solution Explorer, right-click Models -> Add -> Class...
  14. Change the Name to LoanInformation
  15. Click Add
  16. Change the class as follows:
    namespace WattsALoan02.Models
    {
        internal class LoanInformation
        {
            public double principal;
            public double interestRate;
            public double period;
            public double interestAmount;
            public double futureValue;
        }
    }
  17. In the Solution Explorer, right-click Programa.cs -> Rename
  18. Type LoanEvaluation (to get LoanEvaluation.cs) and press Enter
  19. Change the document as follows:
    using WattsALoan.Models;
    using static System.Console;
    
    public class LoanEvaluation
    {
        private Employee        clerk;
        private Customer        client;
        private LoanInformation loan;
    
        public LoanEvaluation()
        {
            clerk  = new Employee();
            client = new Customer();
            loan   = new LoanInformation();
        }
    
        public void IdentifyEmployee()
        {
            WriteLine("Enter the following pieces of information " +
                              "about the employee who prepared this loan.");
            Write("Employee #: ");
            clerk.employeeNumber = long.Parse(ReadLine()!);
            Write("First Name: ");
            clerk.firstName      = ReadLine()!;
            Write("Last Name:  ");
            clerk.lastName       = ReadLine()!;
            Write("Title:      ");
            clerk.title          = ReadLine()!;
        }
    
        public void IdentifyCustomer()
        {
            WriteLine("Enter the following pieces of information " +
                      "about the customer for whom this loan was prepared.");
            Write("Customer Name: ");
            client.fullName    = ReadLine()!;
            Write("Phone Number:  ");
            client.phoneNumber = ReadLine()!;
        }
    
        public void GetLoanValues()
        {
            WriteLine("Enter the following pieces of information " +
                      "about the values used for the loan.");
    
            Write("Enter the principal: ");
            loan.principal    = double.Parse(ReadLine()!);
      
            Write("Enter the interest rate: ");
            loan.interestRate = double.Parse(ReadLine()!) / 100;
    
            Write("Enter the number of months: ");
            loan.period       = double.Parse(ReadLine()!) / 12;
        }
    
        public void Show()
        {
            loan.InterestAmount = loan.principal * loan.interestRate * loan.period;
            loan.FutureValue    = loan.principal + loan.interestAmount;
    
            WriteLine("======================================");
            WriteLine("Loan Summary");
            WriteLine("=------------------------------------=");
            WriteLine("Prepared by:  {0} - {1}\n              {2}",
                              clerk.employeeNumber,
                              clerk.GetEmployeeName(), clerk.title);
            WriteLine("=------------------------------------=");
            WriteLine("Prepared for: {0}\n              {1}",
                              client.fullName, client.phoneNumber);
            WriteLine("=------------------------------------=");
            WriteLine("Principal:       {0:F}", loan.principal);
            WriteLine("Interest Rate:   {0:P}", loan.interestRate);
            WriteLine("Period For:      {0} months", loan.period * 12);
            WriteLine("Interest Amount: {0:F}", loan.interestAmount);
            WriteLine("Future Value:    {0:F}", loan.futureValue);
            WriteLine("======================================");
        }
    }

Previous Copyright © 2010-2026, FunctionX Monday 10 November 2025, 10:56 Next