12月29日学习笔记,常量,枚举的使用
常量:能够设定程序中那些不会被修改的值。如果强行修改,就会报错。
如:class g
{
public const int gs = 100;
}
使用枚举来定义各种属性,先定义一个枚举,然后在枚举里设定各类值
如:// static void Main(string[] arge)
// {
//string[] color = new string[] {"red","black","white" };
//Console.WriteLine("我要选择的颜色是{0}",color[0]);
// }
private enum color
{
red,black,white
}
static void Main(string[] arge)
{
Console.WriteLine("我要选择的颜色是{0}",color.red);
}
注意:枚举的主体里不能定义属性和方法。
浙公网安备 33010602011771号