Which is better between static variable and Application variable?
In my website http://www.hothelpdesk.com , I hope to set a global variable to store domain. so I can access the value in my code anywhere.
I think both Method A and Method B can do that!
In Method A, I use static variable HotHelpDesk.BLL.PublicPar.MyDomain, so I can access the value of HotHelpDesk.BLL.PublicPar.MyDomain in my code anywhere.
In Method B, I use Application["MyDomain"], so I can also access the value of Application["MyDomain"] in my code anywhere.
Could you tell me what different between static variable and Application variable?
Could you tell me which one is better?
Many thanks!
//--------------------------Global.asax------------------------------------------
void Application_Start(object sender, EventArgs e)
{
// Method A
HotHelpDesk.BLL.PublicPar.MyDomain = HotHelpDesk.BLL.Par.GetDomian();
// Method B
Application["MyDomain"] = HotHelpDesk.BLL.PublicClass.GetDomian();
}
//--------------------------Global.asax------------------------------------------
//--------------------------PublicPar.cs-----------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
namespace HotHelpDesk.BLL
{
public class PublicPar
{
public PublicPar()
{
}
public static string MyDomain;
public static string GetDomian()
{
string Full = HttpContext.Current.Request.Url.ToString();
string ToBoot = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath;
ToBoot = ToBoot.Substring(2);
Full = Full.Substring(0, Full.LastIndexOf(ToBoot));
return Full;
}
}
}
//--------------------------PublicPar.cs-----------------------------------------