VS 2005 global.asax 里全局变量调用问题
来源:百度知道 编辑:UC知道 时间:2024/06/01 18:58:19
在2003 global里面
Public Shared Engine As IChatEngine = New ChatEngine
在其他文件 可以 用global.Engine....来用
在2005就不行了,
2005里面要如何搞?
也就是在global里面定义一个静态变量,其他文件进行调用!
不是吧,怎么都是这样的回答!
Public Shared Engine As IChatEngine = New ChatEngine
在其他文件 可以 用global.Engine....来用
在2005就不行了,
2005里面要如何搞?
也就是在global里面定义一个静态变量,其他文件进行调用!
不是吧,怎么都是这样的回答!
Global.asax内容如下:
namespace WebApplication1
{
public class Global : System.Web.HttpApplication
{
public static string UserName;
protected void Application_Start(object sender, EventArgs e)
{
string User = "MyName";
UserName = User;
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
Default.aspx内容如下:
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Global.UserName);
}
}
}
c#没有全局变量,全局变量是面向过程变成的,c#是纯面向对象的!