C# Static Variable 与 Application
Much has been written on C # Static on the network, not much above the
but Static is not there the same effect with the Application? ?
So was tested from the test results can be found
even if different from Client-side browser, Static variables still accumulate up.
static_variable.cs
public class static_variable
{
public static int count; // static
public int number; // nostatic
public static_variable()
{
number = 0;
number++;
count++;
}
public void showData()
{
System.Web.HttpContext.Current.Response.Write("-----------------
");
System.Web.HttpContext.Current.Response.Write(string.Format("count 》{0}
",count));
System.Web.HttpContext.Current.Response.Write(string.Format("number 》{0}
",number));
int count_d = 0;
count_d--;
System.Web.HttpContext.Current.Response.Write(string.Format("count_d 》{0}
",count_d));
}
}
webform.aspx
private void Page_Load(object sender, System.EventArgs e)
{
// 在这里放置使用者程序以初始化网页
// static_variable.count = 0;
static_variable a = new static_variable();
a.showData();
static_variable b = new static_variable();
b.showData();
static_variable c = new static_variable();
c.showData();
}
Original: Large column C # Static Variable and Application