Public Const Vs Public Property

K

Karthik

Dear All,
I have one doubt Regarding Memory ,

I am working on VB .net 2005,

I run the project which has nearly 100 Const variables.

I feel that make all the those const into public shared Propery!

So that i can get the value wherever i want!

Is the above idea reduce the Memory?

Is there any other Idea?

All the words that you send to me is highly appreciated

Thanks in advance



Regards
Karthik.C
 
M

Marc Gravell

So that i can get the value wherever i want!
Well, a const can be public too.
Is there any other Idea?
a const and a public static (shared) property work differently; const
values are read at compile-time, where-as properties are read at
runtime. What this means is that if I declare a value in assembly A,
and consume it from B... then I change the value:
* with a static (shared) property, you rebuild and deploy A; as long
as B loads the assembly it should pick up the new value
* with "const", you need to rebuild B for the change to take affect

Marc
 
M

Michael D. Ober

Marc Gravell said:
Well, a const can be public too.

a const and a public static (shared) property work differently; const
values are read at compile-time, where-as properties are read at runtime.
What this means is that if I declare a value in assembly A, and consume it
from B... then I change the value:
* with a static (shared) property, you rebuild and deploy A; as long as B
loads the assembly it should pick up the new value
* with "const", you need to rebuild B for the change to take affect

Marc

This difference has an impact with databinding to grids and tables.
Constants, because they are read at compile time, cannot be databound
because the databinding actually occurs at runtime. Properties can be
databound because they are computed at runtime.

Mike.
 
M

Marc Gravell

Constants, because they are read at compile time, cannot be
databound because the databinding actually occurs at runtime.
Properties can be databound because they are computed at runtime.
True, but the OP stated "shared" property, which I interpret as
meaning static - you can't really data-bind to static properties
without cheating...
Granted, you could have an instance property (getter) that returns the
value of a static field, but it would be a bit hacky...

Marc
 

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

Top