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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C# - Static vs. Const 5
const and readonly 5
Get Strings 3
Static const. 5
section 1
Modify a const string via reflection/unsafe code? 2
const 16
Visibility query 4

Back
Top