在C#中,要定义一个静态常量,你需要使用static const
关键字。常量的值在编译时就已经确定,因此不能进行修改。下面是一个定义静态常量的示例:
public class MyClass
{
// 定义一个静态常量
public static const int MyConstant = 10;
}
在这个例子中,我们定义了一个名为MyConstant
的静态常量,类型为int
,值为10。由于它是常量,所以它的值不能在其他地方被修改。
在C#中,要定义一个静态常量,你需要使用static const
关键字。常量的值在编译时就已经确定,因此不能进行修改。下面是一个定义静态常量的示例:
public class MyClass
{
// 定义一个静态常量
public static const int MyConstant = 10;
}
在这个例子中,我们定义了一个名为MyConstant
的静态常量,类型为int
,值为10。由于它是常量,所以它的值不能在其他地方被修改。