目前,我不得不把 int
转换成 string
并存储在缓存中,非常复杂。
int test = 123;
System.Web.HttpContext.Current.Cache.Insert("key", test.ToString()); // to save the cache
test = Int32.Parse(System.Web.HttpContext.Current.Cache.Get("key").ToString()); // to get the cache
有没有一种更快的方法,而不需要反复更改类型?
test = (int)HttpContext.Current.Cache.Get("key");
出现错误,无法将string
类型转换为int
,必须使用Parse
,而要使用Parse
,必须先使用.ToString()
。 - Eric Yintypeof(HttpContext.Current.Cache.Get("key")).ToString()
是什么? - spendernull
,而(int)null
会报错。 - Eric Yin