How to define constants in Visual C# like #define in C?

后端 未结 7 898
情歌与酒
情歌与酒 2020-12-29 18:53

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

相关标签:
7条回答
  • 2020-12-29 19:54

    in c language: #define (e.g. #define counter 100)

    in assembly language: equ (e.g. counter equ 100)

    in c# language: according to msdn refrence: You use #define to define a symbol. When you use the symbol as the expression that's passed to the #if directive, the expression will evaluate to true, as the following example shows:

    # define DEBUG

    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.

    0 讨论(0)
提交回复
热议问题