今儿和引用干上了就……
using System;
using System.Web;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Caching;
引用了system.web了,可是敲入关键字cache后,出来的提示下来菜单中,就四个选项,没有get方法,get方法不就是在caching中吗?不知道这是怎么回事?

解决方案 »

  1.   

    string str=(string)Cache.Get("A");
    Response.Write(str);重新引用看看
      

  2.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Web.Caching.Cache cache=new System.Web.Caching.Cache();
            cache.Get(key);
        }
      
    }没问题的,引用了System.Web.
      

  3.   

    private static SqlConnection CreateSqlConnection()
    {
         string conSrt = (string)Cache.Get(connectionStringNameInWebConfig);
    }
    我这样写的,可是就调用不了cache的函数,如果新建的话,就找不到以前存在的信息吧?
      

  4.   

    private static SqlConnection CreateSqlConnection() 

        string conSrt = (string)Cache.Get(connectionStringNameInWebConfig); 

    我这样写的,可是就调用不了cache的全部函数,只能出现四个函数
      

  5.   

    错误信息是这样的
    An object reference is required for the non-static field, method, or property 'System.Web.Caching.Cache.Get(string)'
      

  6.   

    你的connectionStringNameInWebConfig  是静态的?
      

  7.   

    恩,对。
    我觉得和connectionStringNameInWebConfig的静态与否没关系啊,cache是个类,我这个函数又是静态函数,所以要调用的时候肯定要有个实例,关键是,我如果新建一个cache对象,这个新建的cache对象里边也没东西啊,我那句话也就没意义了……
      

  8.   

    An object reference is required for the non-static field, method, or property 'System.Web.Caching.Cache.Get(string)'他说了必须是non-static,非静态的
      

  9.   

    恩,我现在按照书上在做的是一个基础工程,是一个c#工程,就你刚才给出的代码,在一个website中,声明完了的cache就能够使用,所有的方法都能出来,但是如果在c#工程中,只能出来四个……
      

  10.   

    假如我新定义一个cache,就像你刚才那样定义的,我调用get方法的时候,是不是什么都获得不了啊?因为他是刚刚才声明的?
      

  11.   

       "string conSrt = (string)Cache.Get(connectionStringNameInWebConfignon)"
    Cache 是System.Web.Caching 派生出来的类,它不支持静态方法所以有" non-static field,"的提示错误...
    楼主注意了你需要的的是cache(一个System.Web.Caching.Cache对象) 可是你输入的"Cache(有大写)"是一个派生类...System.Web.Caching.Cache的Get(string)方法只能是实例化先再调用
    修改方法同上面3楼的:
     System.Web.Caching.Cache cache=new System.Web.Caching.Cache();////建立一个cache对象
     cache.Get(connectionStringNameInWebConfignon);////通过对象调用方法
      

  12.   

    谢谢啊,看来还是要去msdn看看cache,真不知道这书上是怎么通过编译的
      

  13.   

    谢谢啊,看来还是要去msdn看看cache,真不知道这书上是怎么通过编译的
      

  14.   

    我刚刚试了下..在文件头部引用这个看看
    using System.Web.Caching;然后不许要自定义对象就可以调用Get()方法了