Bill Blogs in C#

Bill Wagner discusses C#, LINQ, and other items of interest

Effective C# Book Discussion page opened
I've opened a blog for reader Q & A (and errata *sigh*).

I’ve added the first reader Q & A item to the Effective C# book blog:

In the section on Conditionals you say that in order to create a method that will fire if more than one condition is true (logical AND), you need to use

#if (VAR1 && VAR2)

#define BOTH

#endif

However, it is possible to chain the conditionals together (according to MSDN, anyway…)

<QUOTE from=”MSDN”>

[Conditional("A")] public static void IfAandB( )

{

   AandBPrivate( );

}

[Conditional("B")] static void AandBPrivate( )

{

   /* Code to execute when both A and B are defined... */

}

Call IfAandB; if both A and B are defined, AandBPrivate will execute.

</QUOTE>

Is there any reason to use your method above the MS one? 

You can read the full answer here:



The Effective C# Book Blog
Discussions on Effective C#
The Effective C# Book Blog RSS Feed
Subscribe for news and information
The first question
Conditional attributes

Published Tuesday, January 11, 2005 7:07 PM by wwagner
Filed under:

Comments

No Comments