Solved

preprocessir directives

Posted on 2006-11-09
2
213 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
ID: 17906935
#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
ID: 17906947
The above from MSDN C# Programmers Reference...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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