Emmm... First there is a difference between const and readonly and it
has to do with versioning or whether the value is updated at runtime or
only if you recompile the _caller_.
http://www.geocities.com/jeff_louie/OOP/oop5.htm
6) Const is Hard Coded Into the Caller and not Version-able
I find this one a bit weird. A const field value is hard coded into the
caller for optimization so that the value is not updated until you
recompile the caller. If you want to version-able read only field
declare it readonly. Finally, you can provide a get only Property like
this:
public string ModelName
{
get
{
return modelName; // danger, return ModelName --> stack
overflow!
}
}
As for static.
http://www.geocities.com/jeff_louie/OOP/oop4.htm
What Is a Static Field or Method?
Let's change the question. When is a field or method not part of an
object? Answer: when it is part of the class! Remember, an object is an
instance of a class and each object exists in a separate space in
memory. It is possible to access class fields and class methods without
creating an instance of a class using the "static" key word. Declaring a
field or method with the static key word, tells the compiler that the
field or method is associated with the class itself, not with instances
of the class. In a sense, static or "class" fields and methods are
global variables and methods that you can touch using the class name. If
you think of a class as a blueprint used to create objects, then you can
think of static fields and methods are being part of the blueprint
itself. There is only one copy of the static fields and methods in
memory, shared by all instances of the class.
Hope that helps,
Jeff
Emm, being a newbie to C#, can someone explain to me what is the
difference between a constant (as a Class member) and a read only
property??<