tags:

views:

443

answers:

3

In C you can define constants like this

#define NUMBER 9

so that wherever NUMBER appears in the program it is replaced with 9. But Visual C# doesn't do this. How is it done?

+6  A: 

You can't do this in C#. Use a const int instead.

Mark Byers
+10  A: 
public const int NUMBER = 9;

You'd need to put it in a class somewhere, and the usage would be ClassName.NUMBER

Jimmeh
+5  A: 

Check How to: Define Constants in C# on MSDN:

In C# the #define preprocessor directive cannot be used to define constants in the way that is typically used in C and C++.

Vinz