所需的非静态字段,方法或属性的对象引用 [英] Object reference required for non-static field, method, or property

查看:1052
本文介绍了所需的非静态字段,方法或属性的对象引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的Caching.Cache(...)方法,像这样:

I want to use the Caching.Cache(...) method, like so:

Cache.Insert("Interview Questions", datatable, sqlcachedep)

System.Web.Caching.Cache.Insert("Reading List", datatable, sqlcachedep);

有与变量没有问题,但我得到在任何情况下,这个错误消息:

There is no problem with the variables, but I get this error message in either case:

错误1 - 一个对象引用所需的非静态字段,方法或属性System.Web.Caching.Cache.Insert(串,对象,System.Web.Caching.CacheDependency)

Error 1 - An object reference is required for the non-static field, method, or property 'System.Web.Caching.Cache.Insert(string, object, System.Web.Caching.CacheDependency)'

我该如何解决这个问题?

How can I fix this?

感谢

推荐答案

它说正确的事情。你应该尝试是这样的:

It's saying the correct thing. You should try something like:

HttpContext.Current.Cache.Insert(...);

Cache.Insert 是不是一个静态方法(静态方法由一个表示S附近文档中的法图标。)您需要一个实例来调用上插入方法。 HttpContext.Current.Cache 返回与当前应用程序相关的缓存对象。

Cache.Insert is a not a static method (static methods are indicated by an "S" near the method icon in the documentation.) You need an instance to call the Insert method on. HttpContext.Current.Cache returns the Cache object associated with the current application.

这篇关于所需的非静态字段,方法或属性的对象引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆