static variables in asp.net/C#

后端 未结 5 820
夕颜
夕颜 2021-01-02 03:24

I\'m using extensively static variables in my web application project. Now I have read from some articles that it is a global variable for the whole project and the data tha

5条回答
  •  时光说笑
    2021-01-02 03:56

    Personally I try to avoid static variables as much as possible. They make the code difficult to unit test and also could introduce subtle bugs due to concurrent access and race conditions.

    As far as your requirement is concerned you could use store the variable as a property of the control in the ViewState. If it is user specific data that you are trying to store then you could use the Session state.

提交回复
热议问题