Global variables in c#.net

后端 未结 6 1687
长情又很酷
长情又很酷 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

    I second jdk's answer: any public static member of any class of your application can be considered as a "global variable".

    However, do note that this is an ASP.NET application, and as such, it's a multi-threaded context for your global variables. Therefore, you should use some locking mechanism when you update and/or read the data to/from these variables. Otherwise, you might get your data in a corrupted state.

提交回复
热议问题