const Vs static

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm having trouble trying to define the difference between declaring a field
in a class const or static. i've noted that when referencing them from the
class that a const is symbolized with a field symbol & a static has a blue
box. What is the difference? What is the blue box? Has it got to do with
scope or get/setability?

Thanks for your thoughts in advance

Ant
 
Ant said:
I'm having trouble trying to define the difference between declaring a field
in a class const or static. i've noted that when referencing them from the
class that a const is symbolized with a field symbol & a static has a blue
box. What is the difference? What is the blue box? Has it got to do with
scope or get/setability?

The value of a const is compiled into any class which uses it, rather
than referencing the value at runtime. The potentially makes it more
efficient, but at the cost that if they're in different assemblies and
you change the value of the const, you have to recompile the other
assembly in order to see the change.
 
Hi Ant,

a const has a value, that is known at compiletime. That value can't change
while runtime and
can be part of a constant expression.
static is a member, that belongs to a class/struct not to an instance of
that class/struct.
A static field is a variable that exists once per application, whil instance
variables exist once per instance.
The value of a static variable can change during runtime.

Christof
 
Back
Top