SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist FCC's Avatar
    Join Date
    May 2006
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP.NET C# - Including a file of constants

    Hello all,

    Right now, I have like a flat file which contains a bunch of constants like:

    Code:
    const int test1 = 1;
    const int test2 = 2;
    const int test3 = 3;
    Now I would like to like include this file in several .cs classes so that they all may use the same constants. How would I go about this? I come from a php background so I guess (for those who are familiar with PHP) I am really looking for a include() function?

    thanks

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    ASP.NET is compiled, not streamed, so you just need to make a static class to contain the constants:

    Code:
    public static class Constants
    {
       public const string Whut="ever";
       public const int Truth=42;
    }
    That said, you probably want an enum if you are storing magic numbers and such.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •