Global variables in c#.net

后端 未结 6 1681
长情又很酷
长情又很酷 2020-11-28 05:08

How can I set a global variable in a C# web application?

What I want to do is to set a variable on a page (master page maybe) and access this variable from any page.

6条回答
  •  渐次进展
    2020-11-28 05:46

    /// 
    /// Contains global variables for project.
    /// 
    public static class GlobalVar
    {
    /// 
    /// Global variable that is constant.
    /// 
    public const string GlobalString = "Important Text";
    
    /// 
    /// Static value protected by access routine.
    /// 
    static int _globalValue;
    
    /// 
    /// Access routine for global variable.
    /// 
    public static int GlobalValue
    {
    get
    {
        return _globalValue;
    }
    set
    {
        _globalValue = value;
    }
    }
    
    /// 
    /// Global static field.
    /// 
    public static bool GlobalBoolean;
    }
    

提交回复
热议问题