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. A very beginer question

A very beginer question

Scheduled Pinned Locked Moved C#
questioncsharplearning
4 Posts 3 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.
  • A Offline
    A Offline
    allende
    wrote on last edited by
    #1

    Hello..I'm trying to make my first console app in c#. I've just read a very good book and some articles. So, I'm sure many of my fistr questions may seem very dumb for most of you...please don't be so hard ;o) Q: I sow that to declare a constant value, it should be declared indide a class. So...what if I want to declare a constant value with scope in my whole app?..should I declare a big class envolving all the code?. Is this a good practice valid even for console and windows apps? Thanks

    L J 2 Replies Last reply
    0
    • A allende

      Hello..I'm trying to make my first console app in c#. I've just read a very good book and some articles. So, I'm sure many of my fistr questions may seem very dumb for most of you...please don't be so hard ;o) Q: I sow that to declare a constant value, it should be declared indide a class. So...what if I want to declare a constant value with scope in my whole app?..should I declare a big class envolving all the code?. Is this a good practice valid even for console and windows apps? Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You could do a class like that:

      public class Constants
      {
      static const int MIN_SOMETHING = 5;
      }

      You can then access them in your whole project like that: int test = Constants.MIN_SOMETHING; This is okay for the most important global constants/variables you might need. But don't populate a class just full of static methods to act like an old C program ;) regards

      1 Reply Last reply
      0
      • A allende

        Hello..I'm trying to make my first console app in c#. I've just read a very good book and some articles. So, I'm sure many of my fistr questions may seem very dumb for most of you...please don't be so hard ;o) Q: I sow that to declare a constant value, it should be declared indide a class. So...what if I want to declare a constant value with scope in my whole app?..should I declare a big class envolving all the code?. Is this a good practice valid even for console and windows apps? Thanks

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        Perhaps an enum is what you're looking for?

        public enum Priorities
        {
        High = 10,
        Medium = 5,
        Low = 1
        }

        ...

        // When you need to use it:
        int priority = (int)Priorities.High;

        Typically, you don't deal with "globals" per se; everything is contained in a class. Now, if you truely do need a 1 instance class with values in those, you can look into using a static class. But there are only rare occassions for this; whenever I see lots of static classes, especially those that share state between other classes, I immediately think "bad design".

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        A 1 Reply Last reply
        0
        • J Judah Gabriel Himango

          Perhaps an enum is what you're looking for?

          public enum Priorities
          {
          High = 10,
          Medium = 5,
          Low = 1
          }

          ...

          // When you need to use it:
          int priority = (int)Priorities.High;

          Typically, you don't deal with "globals" per se; everything is contained in a class. Now, if you truely do need a 1 instance class with values in those, you can look into using a static class. But there are only rare occassions for this; whenever I see lots of static classes, especially those that share state between other classes, I immediately think "bad design".

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Messianic Instrumentals (with audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          A Offline
          A Offline
          allende
          wrote on last edited by
          #4

          Oh, thanks a lot friends(both of you). I'm happy to find a place to ask my newbie's and more advenced quiestions. You're very kind. -- modified at 17:28 Saturday 12th August, 2006

          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