Link to home
Create AccountLog in
Avatar of Rama Tito
Rama TitoFlag for Malaysia

asked on

how to use #define in window form in C#

Hi,

Every time when i declare #define TITO 2;
error message -> cannot define/ undefine preprocessor sysmbols after first token file. Is there any error on define method?
Avatar of utapyngo
utapyngo
Flag of Russian Federation image

1. The #define and #undef preprocessor directives must be used at the beginning of a program, before any other keywords, such as those used in the namespace declaration.
2. The #define directive cannot be used to declare constant values as is typically done in C and C++. Constants in C# are best defined as static members of a class or struct. If you have several such constants, consider creating a separate "Constants" class to hold them.

See:
http://msdn.microsoft.com/en-us/library/47hya4cw%28v=vs.71%29.aspx
http://msdn.microsoft.com/ru-ru/library/yt3yck0x.aspx
Avatar of Rama Tito

ASKER

Thats mean i can't declare #define. Instead of using #define, i must use public const ?
Avatar of Bob Learned
What are you using the #define for?  If you are trying to use it for conditional compilation, then there are other ways to define...
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer