由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - C# interview question
相关主题
.net 2003竟然不支持类中静态变量Question about struct
那位大侠能介绍一下 property in c# class的使用经验how to use Ping() class?
C#中的Memory控制大牛指教:新手List<>问题
好像c#为了DotNet牺牲了不少Re: 请问DATAGRID里的BOUNDCOLUMN HEADER可以又有TE
请教:Asp.net如何给jq class 赋值A question seeking answers
新手请教问题A quick question about Access..
authenticationAnyone knows a simple solution to this in vb.net?
数据库讲座 ---- 得给Beijing mm 还债了 (转载)Linq to entity framework: what happens if i modified DB schema in SSMS ?
相关话题的讨论汇总
话题: const话题: readonly话题: c#话题: field话题: count
进入DotNet版参与讨论
1 (共1页)
E*******s
发帖数: 42
1
what is difference between const and readonly?
st
发帖数: 1685
2
what's the real use for the difference?
I found below URL:
http://www.c-sharpcenter.com/Tutorial/ConstVsReadOnly.htm

【在 E*******s 的大作中提到】
: what is difference between const and readonly?
s*i
发帖数: 5025
3
Example: Suppose we have an ArrayList. Its filed "Count" is readonly, but
definitly not "const".

【在 st 的大作中提到】
: what's the real use for the difference?
: I found below URL:
: http://www.c-sharpcenter.com/Tutorial/ConstVsReadOnly.htm

a**y
发帖数: 335
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?
C****n
发帖数: 2324
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. :)
st
发帖数: 1685
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".

g*****g
发帖数: 34805
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?
st
发帖数: 1685
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.

s*i
发帖数: 5025
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

L*******r
发帖数: 1011
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

a**y
发帖数: 335
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

1 (共1页)
进入DotNet版参与讨论
相关主题
Linq to entity framework: what happens if i modified DB schema in SSMS ?请教:Asp.net如何给jq class 赋值
const reference in copy constructor新手请教问题
C++ Q61: 如何对const data member做assignment?authentication
C++: Q75 copy constructor 问什么用 const reference?数据库讲座 ---- 得给Beijing mm 还债了 (转载)
.net 2003竟然不支持类中静态变量Question about struct
那位大侠能介绍一下 property in c# class的使用经验how to use Ping() class?
C#中的Memory控制大牛指教:新手List<>问题
好像c#为了DotNet牺牲了不少Re: 请问DATAGRID里的BOUNDCOLUMN HEADER可以又有TE
相关话题的讨论汇总
话题: const话题: readonly话题: c#话题: field话题: count