public static ArrayList NewsList(int id)
    {
        string cachekey = "NewsList" + id.ToString();
if(HttpRuntime.Cache[cachekey] == null)
{
            HttpRuntime.Cache.Insert(cachekey,Test.DAL.NewsList(id),null,DateTime.Now.AddHours(1),TimeSpan.Zero);
}
return (ArrayList)HttpRuntime.Cache[cachekey];
}
上面的编译可以通过下面的为什么不能通过?
public static ArrayList NewsList(int id,out int num)
    {
        string cachekey = "NewsList" + id.ToString();
if(HttpRuntime.Cache[cachekey] == null)
{
            HttpRuntime.Cache.Insert(cachekey,Test.DAL.NewsList(id,out num),null,DateTime.Now.AddHours(1),TimeSpan.Zero);
}
return (ArrayList)HttpRuntime.Cache[cachekey];
}

解决方案 »

  1.   

    有什么办法可以缓存带out的方法吗?
      

  2.   

    这与 Cache.Insert  没有关系,是你的  NewsList(int id) 根本就没有 out类型 参数
     
      

  3.   

    public static ArrayList NewsList(int id,out int num)
        {
            num = 0;
            string cachekey = "NewsList" + id.ToString();
        if(HttpRuntime.Cache[cachekey] == null)
        {
                HttpRuntime.Cache.Insert(cachekey,Test.DAL.NewsList(id,out num),null,DateTime.Now.AddHours(1),TimeSpan.Zero);
        }
        
        return (ArrayList)HttpRuntime.Cache[cachekey];
    }
      

  4.   


    把 num 固定为0了,这个不符合我的要求啊。
    没其它办法了吗?
      

  5.   

    方法必须对 out 参数进行初始化!!!当你的 (HttpRuntime.Cache[cachekey] == null)  成立的时候 num  就不是 0 了
      

  6.   

    是的,这个num是查询数据库得出的数值,我一定要得到真实值才行的。
    看来不行了。