There is an equivalent, use const. (Note that a const can not be static)
According to the C# lang spec at [1]:
"Whenever an expression is of one of the types listed above and contains
only the constructs listed above, the expression is evaluated at compile-
time. This is true even if the expression is a sub-expression of a larger
expression that contains non-constant constructs."
This means that constants are replaced at compile time, just like #define's
are. CMIIAW but the following code should print "HelloWorld the answer is 42
:
public class MyConstants
{
public const int TweeEnVeertig = 42;
public const string HalloWereld = "HelloWorld";
}
class Question
{
}
I hope that answer the question,
Robert
[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/csspec/html/vclrfcsharpspec_7_15.asp
On Wed, 3 Jul 2002 16:41:56 -0700, Noam Arbel <[EMAIL PROTECTED]> wrote:
>Hello,
>
>I have a conceptual question:
>
>In C++ we used to do
>
>#define THIS_VAL 10
>#define MAX_THAT 255
>
>and so on. Those where substituted by the compiler with no runtime cost.
>
>Is the an equivalent in C#?
>
>One solution is to create a class with all static const variables (it that
>even allowed?). But there are 2 issues with that; one is that the
>assignment is done at runtime (or is the compiler smart enough to assign
>at compile time). The second is that this class takes up memory.
>
>Any better ideas?
>
>
>thanks,
>
>Noam
>
>You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.