1

I have something like this:

...
public partial class MyPage : System.Web.UI.Page
{

    private static string _code = null;
...

Will the _code variable be shared with everyone on my application who loads MyPage?

This question is not a Duplicate

The possible duplicate does not address static variables inside a non-static class. I now know it does not matter, however, the "duplicate" does not say this.

capdragon
  • 14,565
  • 24
  • 107
  • 153
  • 2
    possible duplicate of [How do static properties work in an asp.net enviroment?](http://stackoverflow.com/questions/4026785/how-do-static-properties-work-in-an-asp-net-enviroment) – asawyer Jun 05 '12 at 15:42
  • @finnw I said `_code` variable in my question but was originally going to have it as a property when I was writing the title... SO SORRY! (downvote? really?) – capdragon Jun 05 '12 at 16:07
  • I did not downvote you (but I did vote to close as duplicate.) – finnw Jun 05 '12 at 16:08
  • @asawyer The "duplicate" does not address static variables inside a non-static class. I now know it does not matter, however, you're "duplicate" does not say this. – capdragon Jun 05 '12 at 16:10
  • @capdragon I'm sorry if you don't agree, and I did not downvote. The question, in my opinion is an duplicate because it addresses static value behavior in asp.net applications. I had asked the same thing before and thought the information I received would be useful to you. The close vote is simply the mechanism provided. There is no reason to get bent out of shape. – asawyer Jun 05 '12 at 17:11
  • I still think it's a duplicate. The difference is not significant enough to justify a separate question. – finnw Jun 05 '12 at 18:09
  • 1
    i think this is a very useful question and is helping me figure out if i can do that is said in question. – f1wade Oct 04 '12 at 11:11

2 Answers2

3

yes, static members of non static classes are anyway static.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
2

Yes, it will be shared across the application domain. Since a single app domain is created for each IIS Application within an IIS worker thread, the value of the static variable can be considered shared globally.

BrokenGlass
  • 158,293
  • 28
  • 286
  • 335