Solved

preprocessir directives

Posted on 2006-11-09
2
209 Views
Last Modified: 2008-02-07
Does C# have anything like in C -

#ifndef BLAH

#define BLAH
.......
.......
#endif

in C# I've tried #if (!BLAH)  #if (BLAH == false), both of which do not compile.

Naturally I can just say  #if BLAH  #else ..........  #endif, but I was wondering if C# supported the other.  Thanks
0
Comment
Question by:ARACK04
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
Comment Utility
#if symbol [operator symbol]...
where:

symbol
The name of the symbol you want to test. You can also use true and false. symbol can be prefaced with the negation operator. For example, !true will evaluate to false.
operator (optional)
You can use the following operators to evaluate multiple symbols:
== (equality)

!= (inequality)

&& (and)

|| (or)

You can group symbols and operators with parentheses.

// preprocessor_if.cs
#define DEBUG
#define VC_V7
using System;
public class MyClass
{
   public static void Main()
   {

      #if (DEBUG && !VC_V7)
         Console.WriteLine("DEBUG is defined");
      #elif (!DEBUG && VC_V7)
         Console.WriteLine("VC_V7 is defined");
      #elif (DEBUG && VC_V7)
         Console.WriteLine("DEBUG and VC_V7 are defined");
      #else
         Console.WriteLine("DEBUG and VC_V7 are not defined");
      #endif
   }
}
0
 
LVL 15

Expert Comment

by:ozymandias
Comment Utility
The above from MSDN C# Programmers Reference...
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now