如何在C中定义的#define一样在Visual C#中的常量? [英] How to define constants in Visual C# like #define in C?

查看:358
本文介绍了如何在C中定义的#define一样在Visual C#中的常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C,可这样定义的常量

 的#define 9号

,这样无论数字出现在它被替换9.但Visual C#不这样做的计划。 ?它是怎么做的。


解决方案

 公共const int的NUMBER = 9; 

您就需要把它放在一个地方类和用法是 ClassName.NUMBER


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 C# doesn't do this. How is it done?

解决方案

public const int NUMBER = 9;

You'd need to put it in a class somewhere, and the usage would be ClassName.NUMBER

这篇关于如何在C中定义的#define一样在Visual C#中的常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆