如何申报在C#中的局部常量? [英] How to declare a local constant in C#?

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

问题描述

如何申报在C#局部常量?

How to declare a local constant in C# ?

就像在Java中,你可以做到以下几点:

Like in Java, you can do the following :

public void f(){
  final int n = getNum(); // n declared constant
}



如何做到在C#中的一样吗?我试着用只读常量但没有一个似乎工作。

How to do the same in C# ? I tried with readonly and const but none seems to work.

任何帮助将不胜感激。

感谢。

推荐答案

在C#中,你不能创建一个从方法检索一个常数。

In C#, you cannot create a constant that is retrieved from a method.

http://msdn.microsoft.com/en-us/library/e6w8fe1b(VS.71).aspx

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

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