Chapter 11

Input Validation, Debugging, and Instrumentation

What You Will Learn in This Chapter

  • Understanding validation input
  • Using regular expressions
  • Managing data integrity
  • Using preprocessor directives and symbols
  • Using the Debug and Trace classes
  • Tracing, logging, and profiling


You can find the code downloads for this chapter at on the Download Code tab. The code is in the chapter11 download and individually named according to the names throughout the chapter.

This chapter explains several topics that at first may seem unrelated. It starts by discussing input validation techniques that a program can use to protect itself from bad values entered by the user.

After the data has entered the program, you still need to manage the data so that it doesn’t become corrupted by incorrect calculations. A useful method to do this is to use preprocessor directives to include testing code during debug builds, but to exclude it from release builds.

That same technique of using preprocessor directives is also useful for studying the program’s activities and performance. It enables you to include or exclude code that traces execution, logs progress, and profiles the application’s performance during the appropriate releases.

This chapter introduces all these topics: input validation, managing data integrity, tracing, logging, profiling, and preprocessor directives that you can use to determine which of those ...

Get MCSD Certification Toolkit (Exam 70-483): Programming in C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.