Solved

preprocessir directives

Posted on 2006-11-09
2
210 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

15 Experts available now in Live!

Get 1:1 Help Now