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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Exposing global data

Exposing global data

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 1 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.
  • 1 Offline
    1 Offline
    1nsp1r3d
    wrote on last edited by
    #1

    Hi all, I want to expose some global strings/ints so I wondered should I be using public const int i = 5; or public static int i = 5;? Thanks. Regards, gamehack

    C J G 3 Replies Last reply
    0
    • 1 1nsp1r3d

      Hi all, I want to expose some global strings/ints so I wondered should I be using public const int i = 5; or public static int i = 5;? Thanks. Regards, gamehack

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      It depends. Will this data be used within a class instance ? If so, no need to make it static. Are static and const mutually exclusive ? I don't think so. I think it should be const no matter what. Christian Graus - Microsoft MVP - C++

      1 1 Reply Last reply
      0
      • C Christian Graus

        It depends. Will this data be used within a class instance ? If so, no need to make it static. Are static and const mutually exclusive ? I don't think so. I think it should be const no matter what. Christian Graus - Microsoft MVP - C++

        1 Offline
        1 Offline
        1nsp1r3d
        wrote on last edited by
        #3

        Thanks :)

        1 Reply Last reply
        0
        • 1 1nsp1r3d

          Hi all, I want to expose some global strings/ints so I wondered should I be using public const int i = 5; or public static int i = 5;? Thanks. Regards, gamehack

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          Be aware that "const" is resolved like at compile time like a C/C++ define. This means that if you change the value, other assemblies will still have the original value. "const" is fabulous for internal data, but lousy otherwise. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

          1 Reply Last reply
          0
          • 1 1nsp1r3d

            Hi all, I want to expose some global strings/ints so I wondered should I be using public const int i = 5; or public static int i = 5;? Thanks. Regards, gamehack

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            A constant can not be declared as static. All constants are static. A constant is not a variable as such but rather a compiler directive. Unless the constant is an object (e.g. a string), it's never stored as data. If you declare a constant: const int foo = 42; This line: bar = foo; will produce exactly the same code as: bar = 42; --- b { font-weight: normal; }

            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