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

后端 未结 7 909
情歌与酒
情歌与酒 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:49

    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;  
    }
    

提交回复
热议问题