|
-
Oct 16th, 2004, 10:32 AM
#1
Thread Starter
Banned
constant
How do I create a constant in a vb.net class?
All i want to do is something like:
Public Const strPath as String = "\\machine\blah\foo"
Is that right ???
I want to use strPath in several functions and dont want to keep hardcoding that path name.
Thanks
-
Oct 16th, 2004, 12:16 PM
#2
Frenzied Member
That syntax is correct, as far as I can tell. To be honest, I dont quite get the advantage of constants over just a plain variable, especially if it's exposed as a property. I guess it makes sense for something like PI, which will never change, but paths well could change.
-
Oct 16th, 2004, 11:24 PM
#3
Thread Starter
Banned
Originally posted by Mike Hildner
That syntax is correct, as far as I can tell. To be honest, I dont quite get the advantage of constants over just a plain variable, especially if it's exposed as a property. I guess it makes sense for something like PI, which will never change, but paths well could change.
Exactly...so if they do change why should i recode them in every place rather than one constant ???
-
Oct 17th, 2004, 12:01 AM
#4
Something like this could go into the web.config file, so that you can keep changing it without having to recompile each time.
-
Oct 17th, 2004, 01:57 PM
#5
Thread Starter
Banned
Originally posted by mendhak
Something like this could go into the web.config file, so that you can keep changing it without having to recompile each time.
Hmm...
Where in the web config...
can you provide examples....
As well as how to read it back in ??
Is it much like a connection string ?
Web Config does sound tempting...
I take it you just build the tag kinda like the conn string?
-
Oct 17th, 2004, 02:23 PM
#6
Hi,
You really need to search your MSDN or the online version a bit for constant declaration and web.config usage. You'll be amazed by the number of examples you'll find there.
Cheers,
NTG
Last edited by ntg; Oct 17th, 2004 at 05:11 PM.
-
Oct 17th, 2004, 06:30 PM
#7
Frenzied Member
Exactly...so if they do change why should i recode them in every place rather than one constant ???
I don't mean that a variable needs to be defined everywhere, just that a constant is just that. Maybe you really mean a "global" variable and not a constant per se. I don't know.
Your syntax in your original post is correct, and you'll get the constant you need. You could do as suggested (via app.config), and make your "constant" well, "variable" .
Really depends on what you need. Seems I remember that defining constants somehow saves memory space.
-
Oct 17th, 2004, 11:23 PM
#8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|