X hits on this document

1059 views

0 shares

0 downloads

0 comments

324 / 396

Chapter ‎18   Unsafe code

using System; using System.Diagnostics;

class Class1 { [Conditional("DEBUG")] public static void M() { Console.WriteLine("Executed Class1.M"); } }

class Class2 { public static void Test() { Class1.M(); } }

declares Class1.M as a conditional method. Class2's Test method calls this method. Since the conditional compilation symbol DEBUG is defined, if Class2.Test is called, it will call M. If the symbol DEBUG had not been defined, then Class2.Test would not call Class1.M.

It is important to note that the inclusion or exclusion of a call to a conditional method is controlled by the conditional compilation symbols at the point of the call. In the example

File class1.cs:

using System.Diagnostics;

class Class1 { [Conditional("DEBUG")] public static void F() { Console.WriteLine("Executed Class1.F"); } }

File class2.cs:

#define DEBUG

class Class2 { public static void G() { Class1.F();// F is called } }

File class3.cs:

#undef DEBUG

class Class3 { public static void H() { Class1.F();// F is not called } }

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.311

Document info
Document views1059
Page views1059
Page last viewedSat Dec 10 17:26:22 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments