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:
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.