The best way to handle keys strings
I'm working in a web applications and always i need to use some keys to save some values into object like :
Session["CurrentUser"] = Users.CurrentUser;
I tried to put them into a resource file but it doesn't make sense as i will not need to localize them and the c开发者_高级运维ode generated by the resource file looks for the culture every time i get a string from the file.
what is the best way to handle those keys in order to avoid spelling mismatches?
I'm using Visual Studio 2010 and ASP.NET MVC2
You could use constants:
public static class Constants
{
public const string CurrentUserKey = "CurrentUser";
}
and then:
Session[Constants.CurrentUserKey] = Users.CurrentUser;
Also the compiler doesn't care much about spelling or grammar mistakes, as long as the strings match he is OK :-)
精彩评论