C#初学者:我的IList.Where()方法去了哪里?

Iai*_*ser 3 c# ilist class where-clause

我有另一个简单的(我认为),这让我很难过.我在我的一个控件中编写了一个方法,根据文件名获取CMS中文件的最新版本(即无论文件所在的文件夹是什么).我发现它很有用,我以为我会把它放在我的CMSToolbox类中,但是当我这样做时,我不能再使用Where()CMS提供的FileManager类的方法(它返回一个列表).

这是我班级的简化示例:

using System;
using System.Collections.Generic;
using CMS.CMS;
using CMS.Core;
using CMS.Web;

namespace CoA.CMS {
    public class ToolBox
    {
        public CMS.CMS.File getLatestFileVersionByFilename(string filename, int GroupID)
        {
            IList<CMS.CMS.File> fileWithName = FileManager.GetGroupAll(false, GroupID).Where(file => currentFileVersionIsNamed(file, filename)).ToList<CMS.CMS.File>();
            return getLatestFileFromListOfFiles(fileWithName);

        }
        protected bool currentFileVersionIsNamed(CMS.CMS.File file, string name)
        {
        }
        protected CMS.CMS.File  getLatestFileFromListOfFiles(CMS.CMS.File file)
        {
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在Control的上下文中完成同样的事情时(实际上是由CMS提供的类扩展Control)我可以访问该Where()方法,但在我的ToolBox类中我没有.是什么赋予了?我认为,IList无论你在哪里使用它,总是允许访问相同的方法.

我又错了,哈哈:)


编辑:Filemanager.GetGroupAll()返回一个CMSList扩展的IList

Joe*_*orn 12

你需要一个using指令System.Linq. .Where()IEnumerable<T>(IList<T>实现)在System.Linq命名空间中定义的扩展方法.