为什么我不能有 "public static const string S = "stuff";在我的课堂上? [英] Why can't I have "public static const string S = "stuff"; in my Class?

查看:28
本文介绍了为什么我不能有 "public static const string S = "stuff";在我的课堂上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试编译我的类时出现错误:

When trying to compile my class I get an error:

常量'NamespaceName.ClassName.CONST_NAME'不能标记为静态.

在线:

public static const string CONST_NAME = "blah";

我可以一直在 Java 中做到这一点.我究竟做错了什么?为什么它不让我这样做?

I could do this all of the time in Java. What am I doing wrong? And why doesn't it let me do this?

推荐答案

const 对象总是 static.

这篇关于为什么我不能有 "public static const string S = "stuff";在我的课堂上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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