Difference between const and readonly

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Amit (remove.amitig_at_hotmail.com)
Date: 02/26/05


Date: Sat, 26 Feb 2005 13:49:03 -0500

Hello,
I have a class where I store a lot of setting names. Right now they're all
declared as consts :
public const CurDoc as string = "CURRENT_DOCUMENT"

>From what I know about const, every call to CurDoc will be replaced with the
text "CURRENT_DOCUMENT" during compilation. Is this right? If yes then
wouldn't it be better to declare it as:
public shared readonly CurDoc as string = "CURRENT_DOCUMENT"

This way there'll be a reference to this string, instead of it being copied
at each access point. What's the best practice for these?
Thanks
Amit



Relevant Pages

  • Re: Public Variables
    ... I store the company name that is displayed on all my forms in a table. ... Is it not better to retrieve the company name at startup ... I declare the variable in a module but can not get a value ... Public Const CompanyName As String = "My Company Name" ...
    (microsoft.public.access.gettingstarted)
  • Re: question on character-like variable defination
    ... No, the above is not a way to declare a variable to store a string, ... But other folk gave the answer (that the numbers declare the length). ... His incorrect presumption that "character file" is ...
    (comp.lang.fortran)
  • Re: UnRAROCX.ocx and unrar.dll
    ... FileName As String * 260 ... Private Type RAROpenArchiveData ... Private Declare Function RARCloseArchive Lib "unrar.dll" (ByVal hArcData As ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with passing parameter
    ... > 1) Your declare for WriteFile is incorrect. ... Since you're using strings you'd alias this API with an "A". ... > 2) You can *not* pass a variant, even if it's type is string, to an API ...
    (microsoft.public.vb.general.discussion)
  • Re: Storing a value for later use in vba or a Macro
    ... Dim strCurrentCustomer as String ... do you programmatically store a value from one record to use in ...
    (microsoft.public.access.gettingstarted)