Chapter 6: Debugging with Visual Studio | 167 |
handling bad data and fixing null references. The program itself is not particularly sophisticated, but it contains just enough logic to lead you down a rat hole and show you how to work your way out. First, we’ll look at the program, and then we’ll follow up with two
A Program with Bugs
The code in this section contains bugs, and it’s important that you type it in as listed or use the downloadable code for this book from the
The program is divided into three major parts: a class to hold customer information, a class that will return a list of customers, and the class containing the Main method that runs the program. The following sections describe each of these classes.
The Customer Class
Any time you are working with data, you’ll have a class to hold that data. Since this application works with customers, the natural approach is to have a Customer class, as follows:
C#:
public class Customer
{
public string FirstName { get; set; } public string LastName { get; set; }
}
VB:
Public Class Customer
Property FirstName As String
Property LastName As String
End Class
This is the minimal information required for this demo, and any class that you build will have more properties. Notice that both properties are type string.