Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Changing amount of a const variable at the run time !

Changing amount of a const variable at the run time !

Scheduled Pinned Locked Moved C#
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi. I wanna know , Can we change amount of a const variable at run time for ever. I mean , when we change the amount, it will be firm even after closing and running the Application again. Thanks

    M K P 3 Replies Last reply
    0
    • M Mohammad Dayyan

      Hi. I wanna know , Can we change amount of a const variable at run time for ever. I mean , when we change the amount, it will be firm even after closing and running the Application again. Thanks

      M Offline
      M Offline
      MNantu
      wrote on last edited by
      #2

      You can use readonly instead of const and you can save that value in an XML file, txt, database etc. Hope this helps :)

      1 Reply Last reply
      0
      • M Mohammad Dayyan

        Hi. I wanna know , Can we change amount of a const variable at run time for ever. I mean , when we change the amount, it will be firm even after closing and running the Application again. Thanks

        K Offline
        K Offline
        King Julien
        wrote on last edited by
        #3

        Hi, I believe changing a CONST type in the runtime is merely impossible... because its a compile-time constanst... If you want to assign a value at runtime only for once and after if you want to deny any changes then you can use readonly. However all this concepts are valid only when the assembly is loaded in to the memory.. means only while the application is running.... Once the application is stopped then, all the variables and objects in the program is lost whatever the type(CONST or ReadOnly doesnt matter). If you want to retain the changes even after the application is closed, then saving the data in a separate file and accessing it, as and when required is the possible solution.

        Have a Happy Coding.....

        1 Reply Last reply
        0
        • M Mohammad Dayyan

          Hi. I wanna know , Can we change amount of a const variable at run time for ever. I mean , when we change the amount, it will be firm even after closing and running the Application again. Thanks

          P Offline
          P Offline
          Phil J Pearson
          wrote on last edited by
          #4

          You can distribute the source file with the application, include some code to parse the source, find the text where the const variable is defined and change it. Then your program merely has to rebuild itself, exit and start the new version. :laugh:

          Phil


          The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups