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

Created: 1/11/2005 9:07:02 PM

Current Projects

I create content for .NET Core. My work appears in the .NET Core documentation site. I'm primarily responsible for the section that will help you learn C#.

All of these projects are Open Source (using the Creative Commons license for content, and the MIT license for code). If you would like to contribute, visit our GitHub Repository. Or, if you have questions, comments, or ideas for improvement, please create an issue for us.

I'm also the president of Humanitarian Toolbox. We build Open Source software that supports Humanitarian Disaster Relief efforts. We'd appreciate any help you can give to our projects. Look at our GitHub home page to see a list of our current projects. See what interests you, and dive in.

Or, if you have a group of volunteers, talk to us about hosting a codeathon event.