
172Microsoft Visual Studio 2010: A Beginner’s Guide
4.Next, set a breakpoint on the if statement,
C#:
cust.FirstName == "Jean"
VB:
cust.FirstName = "Jean"
The goal here is to see what happens when the if statement finds the record matching the searchName. At this point, we’re assuming that Jean does exist in the data. Working with a small program, you can use windows such as Autos, Locals, or Watch to find this record. However, many
5.Press F5 to run the program. You expect to hit the breakpoint, but that won’t happen. Confusing? We know that there isn’t anything wrong with the logic, because the if statement condition is a simple equality operator. Perhaps we’ve looked in the database or whatever source the data came from, but it’s given in this scenario that Jean is definitely in the data. However, this illustrates a common problem where the quality of data you work with is less than desired.
6.This time, change the breakpoint condition on the if statement as follows and
C#:
cust.FirstName.Contains("Jean")
VB:
cust.FirstName.Contains("Jean")
Remember, we suspect bad data, so the call to Contains on the string assumes that there might be some extraneous white space or other characters around the name in the data. Hover over cust.FirstName or look at cust in one of the debug windows to verify it is the record you are looking for. This breakpoint will pause on any records that contain the sequence of characters “Jean”, such as