在C中,你可以像这样定义常量
#define NUMBER 9这样,无论程序中数字出现在哪里,它都会被替换为9。但是Visual C#不会这样做。它是如何做到的?
发布于 2009-11-27 17:59:15
public const int NUMBER = 9;你需要把它放在某个类的某个地方,用法是ClassName.NUMBER
发布于 2009-11-27 17:58:42
在C#中不能这样做。请改用const int。
发布于 2011-10-06 02:44:25
static class Constants
{
public const int MIN_LENGTH = 5;
public const int MIN_WIDTH = 5;
public const int MIN_HEIGHT = 6;
}
// elsewhere
public CBox()
{
length = Constants.MIN_LENGTH;
width = Constants.MIN_WIDTH;
height = Constants.MIN_HEIGHT;
}https://stackoverflow.com/questions/1807785
复制相似问题