您可以将只读字段指定为静态 [英] You can specify a readonly field as static
本文介绍了您可以将只读字段指定为静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对readonly varibles感到困惑
你可以将readonly字段指定为静态
语法明智我怀疑
public readonly int x = 10;
public static int x = 10; < br $>
静态只读int x = 10;
以下约2种语法正确
你可以指定一个只读字段为静态
我尝试过:
public static int x = 10;
static readonly int x = 10;
以下约2种语法对于< pre>是正确的,您可以将只读字段指定为静态
解决方案
< blockquote>变量可以是public,private,internal,protected或protected internal。
除此之外,它可以是静态的或非静态的。
除此之外它只能是readonly或非readonly。
这些组中没有一个排除其他组。
所以你可以有一个公共静态只读变量
i had confused about readonly varibles"
you can specify a readonly field as static
" syntax wise i had doubt
public readonly int x=10;
public static int x=10;
static readonly int x=10;
Following about 2 syntaxes which is correct for
you can specify a readonly field as static
What I have tried:
public static int x=10; static readonly int x=10; Following about 2 syntaxes which is correct for <pre>you can specify a readonly field as static
解决方案
A variable can public, private, internal, protected, or protected internal.
On top of that it can be static or non-static.
As well as that it can be readonly or non-readonly.
None of these groups exclude the others.
so you can have a public static readonly variable
这篇关于您可以将只读字段指定为静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文