Global variable ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • serge calderara

    #1

    Global variable ???

    Dear all,

    What is the best way to handle global variable in .NET?

    We have for instance a configuration file with certain
    application parameters.
    Lets say that sDataBasePath will contain the path of a
    database file set in that configuration file.

    Then how to declare that variable in order that it it
    global to :

    1- the whole assembly
    2- the whole aaplication that is based on different
    assembly

    In VB5 for instance that variable would be declare in
    a .BAS module as Global sDataBasePath as string

    thanks for your answer
    Regards
  • Jon Skeet

    #2
    Re: Global variable ???

    serge calderara <serge.calderar a@maillefer.net > wrote:[color=blue]
    > What is the best way to handle global variable in .NET?[/color]

    Make it a static member of a class.
    [color=blue]
    > We have for instance a configuration file with certain
    > application parameters.
    > Lets say that sDataBasePath will contain the path of a
    > database file set in that configuration file.[/color]

    That sounds like you'd want a Configuration class, with a private
    member called databasePath and a public/internal property to retrieve
    it. You could either make it static, or use the singleton pattern and
    make it an instance variable, which would make it easier to adapt your
    app later to support multiple simultaneous configurations.
    [color=blue]
    > Then how to declare that variable in order that it it
    > global to :
    >
    > 1- the whole assembly[/color]

    Make it internal.
    [color=blue]
    > 2- the whole aaplication that is based on different
    > assembly[/color]

    Make it public.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...