tags:

views:

69

answers:

3

Whats wrong with these pre-processor directive in C#

#define OUTPUT_DIRECTORY "E:\asdf\sdfg\jhkl\"

I also tried giving:

#define OUTPUT_DIRECTORY "E:\\asdf\\sdfg\\jhkl\\"

for both I get error:

Error 1 Single-line comment or end-of-line expected

+4  A: 

You cannot give that symbol (OUTPUT_DIRECTORY) a value, the symbol can only be "defined" or "undefined" so you can use it in a #if OUTPUT_DIRECTORY ... #endif.

See http://msdn.microsoft.com/en-us/library/yt3yck0x(VS.71).aspx

Hans Kesting
+1 i was just typing the same thing =)
David Hedlund
+2  A: 

You define a symbol. You can't assign a value to it.

Symbols are not variables. See more on MSDN.

The usage could be:

 #ifdef OUTPUT_DIRECTORY
   someVariable = "E:\\asdf\\sdfg\\jhkl\\"
 #endif
Oded
then what is `#define PI 3.1428`
pecker
@pecker - that would be C++. In C# we have `Math.PI`, and quite happy with it.
Kobi
It's C or C++, not C#. And it's also approximately 0.0012 greater than pi. ;)
Tim Goodman
+2  A: 

In addition to Oded and Hans' answers, I'd recommend simply making it a constant rather than trying to use the pre-processor. If it's used by multiple classes, define it in a common class.

Richard Szalay