Access the full text.
Sign up today, get DeepDyve free for 14 days.
CHAPTER 39 ■ ■ ■ The .NET runtime provides a few facilities for making programming less dangerous. You can use conditional methods and tracing to add checks and log code to an application, to catch errors during development, and to diagnose errors in released code. Conditional Methods Conditional methods are typically used to write code that performs operations only when compiled in a certain way. This often takes place in order to add code that’s called only when a debug build is made and not when called in other builds, usually because the additional check is too slow. In C++, you’d do this by using a macro in the include file that changes a function call to nothing if the debug symbol isn’t defined. This doesn’t work in C#, however, because there’s no include file or macro. In C#, you can mark a method with the Conditional attribute to indicate when calls to it should be generated. For example: using System; using System.Diagnostics; class MyClass public MyClass(int i) this.i = i; [Conditional("DEBUG")] public void VerifyState() if (i != 0) Console.WriteLine("Bad State"); 473 474 CH APTER 39 ■ DEFENSIVE PROGRAMMING int i = 0; class Test public static void Main()
Published: Jan 1, 2005
Read and print from thousands of top scholarly journals.
Already have an account? Log in
Bookmark this article. You can see your Bookmarks on your DeepDyve Library.
To save an article, log in first, or sign up for a DeepDyve account if you don’t already have one.
Copy and paste the desired citation format or use the link below to download a file formatted for EndNote
Access the full text.
Sign up today, get DeepDyve free for 14 days.
All DeepDyve websites use cookies to improve your online experience. They were placed on your computer when you launched this website. You can change your cookie settings through your browser.