我試圖在一個pagerequest期間用livetime設置一個全局變量。在c#中設置全局變量class
在經典ALS我用這個像這樣:
dim VariableName
VariableName = "test";
sub testsub()
VariableName += VariableName + "new"
response.write VariableName
end sub
response.write VariableName '-> test
testsub() '-> testnew
現在在asp.net我tryed設置變量在我的課是這樣的:
public static class MyClass
{
public static string GlobalVar = "test";
public static string MyMethod()
{
GlobalVar += GlobalVar + "new";
return GlobalVar;
}
}
但是現在,問題是,這個變量就像一個應用變量,其生命週期超過了所有的pagerequest。
在哪裏可以定義一個生命期間的變量,在一個請求期間可用於所有方法和其他類?
這有壞設計寫在它上面 – 2009-12-28 12:53:34