开发者

The best way to handle keys strings

开发者 https://www.devze.com 2023-02-05 17:12 出处:网络
I\'m working in a web applications and always i need to use some keys to save some values into object like :

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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号