也许这个问题应该很容易,但事实并非如此.我在ASP.NET中阅读了使用System.Web.Caching.Cache类的问题.
我有一个单身人士课程:
private System.Web.Caching.Cache _cache;
private static CacheModel _instance = null;
private CacheModel() {
_cache = new Cache();
}
public static CacheModel Instance {
get {
return _instance ?? new CacheModel();
}
}
public void SetCache(string key, object value){
_cache.Insert(key, value);
}
Run Code Online (Sandbox Code Playgroud)
如果,在我的代码中的任何其他位置,我调用以下内容:
CacheModel aCache = CacheModel.Instance;
aCache.SetCache("mykey", new string[2]{"Val1", "Val2"}); //this line throws null exception
Run Code Online (Sandbox Code Playgroud)
为什么第二行抛出空引用异常?
也许我在代码的某个地方犯了一些错误?
谢谢.