avatar
a*y
4
const can not be changed in any case, readonly can not be changed by you. :)

【在 E*******s 的大作中提到】
: what is difference between const and readonly?
avatar
C*n
5
All right guys.
1. Const can not be changed, and can only be declared in the field
declaration.
i.e.: public const int i=5;
2. const automatically means static.
3. Readonly can be asigned in CONSTRUCTOR!
The real world concern:
Never declare a public field as CONST (static), use readonly
instead, which will save you from recompilation if the const in the underlying
library is
recompiled. Only use const with your private field.
Well, a better pratice is never declare public field.
The Count in Ar

【在 a**y 的大作中提到】
: const can not be changed in any case, readonly can not be changed by you. :)
avatar
st
6
well, why you want an arrayList's count field to be readonly?

【在 s*i 的大作中提到】
: Example: Suppose we have an ArrayList. Its filed "Count" is readonly, but
: definitly not "const".

avatar
g*g
7
When you use const, it has to be known by compilation time.
readonly is better, you want to assign the size in initilization.
That size is determined at runtime.

【在 st 的大作中提到】
: well, why you want an arrayList's count field to be readonly?
avatar
st
8
why I ant arrayList count field to be either readonly or const?

【在 g*****g 的大作中提到】
: When you use const, it has to be known by compilation time.
: readonly is better, you want to assign the size in initilization.
: That size is determined at runtime.

avatar
s*i
9
This is a good explanation. I got the concept wrong.

underlying
of

【在 C****n 的大作中提到】
: All right guys.
: 1. Const can not be changed, and can only be declared in the field
: declaration.
: i.e.: public const int i=5;
: 2. const automatically means static.
: 3. Readonly can be asigned in CONSTRUCTOR!
: The real world concern:
: Never declare a public field as CONST (static), use readonly
: instead, which will save you from recompilation if the const in the underlying
: library is

avatar
L*r
10
Your explain is clear. //admire
Actually, just think about the reason why C++ introduces const.
Then we will know the basic feature of const le. :)

underlying
of

【在 C****n 的大作中提到】
: All right guys.
: 1. Const can not be changed, and can only be declared in the field
: declaration.
: i.e.: public const int i=5;
: 2. const automatically means static.
: 3. Readonly can be asigned in CONSTRUCTOR!
: The real world concern:
: Never declare a public field as CONST (static), use readonly
: instead, which will save you from recompilation if the const in the underlying
: library is

avatar
a*y
11
o. I thought the 'readonly' in the question is an attribute
instead of a data type modifier.
And I didn't know C# has a 'readonly' modifier until now. //blush

【在 C****n 的大作中提到】
: All right guys.
: 1. Const can not be changed, and can only be declared in the field
: declaration.
: i.e.: public const int i=5;
: 2. const automatically means static.
: 3. Readonly can be asigned in CONSTRUCTOR!
: The real world concern:
: Never declare a public field as CONST (static), use readonly
: instead, which will save you from recompilation if the const in the underlying
: library is

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。