How do I persist data without global variables?

后端 未结 5 1023
傲寒
傲寒 2020-12-18 00:06

I\'m used to scripting languages. PHP, Javascript etc. and I\'ve written a few relatively simple Java and C# apps. This is a question I\'ve repeatedly needed an answer for,

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 00:21

    In C#, one of the ways to get behavior similar to global variables is to use static class methods and class variables. Static class methods and variables have a single instance in C#, and are somewhat akin to global variables in other languages.

    That said, for your problem, it sounds much more like a design problem. C# is very focused on Object Oriented Design; I'd suspect for the problem you've given that a better OOD would resolve your problem.

提交回复
热议问题