C# 初学者 : Where has my IList. Where() 方法不见了?

标签 c# class where-clause ilist

我有另一个简单的(我认为)难倒了我。我已经在我的一个控件中编写了一个方法,该方法在给定文件名的情况下获取 CMS 中文件的最新版本(即,无论文件位于哪个文件夹)。我发现它非常有用,我想我应该把它放在我的 CMSToolbox 类中,但是当我这样做时,我不能再使用 CMS 提供的 FileManager 类的 Where() 方法(它返回一个列表)。

这是我的类(class)的一个简化示例:

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)
        {
        }
    }
}

当我在控件(实际上是 CMS 提供的扩展 Control 的类)上下文中执行完全相同的操作时,我可以访问 Where()方法,但在我的 ToolBox 类中我没有。是什么赋予了?我认为 IList 将始终允许从您使用它的任何地方访问相同的方法。

我又错了,哈哈:)


编辑:Filemanager.GetGroupAll() 返回一个扩展 IListCMSList

最佳答案

您需要为 System.Linq 使用指令. .Where()IEnumerable<T> 上的扩展方法(IList<T> 实现)在 System.Linq 命名空间中定义。

关于C# 初学者 : Where has my IList. Where() 方法不见了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1760719/

相关文章:

c# - PngBitmapDecoder 流问题

Java 改变不同类的 GUI

Java 从泛型 Class 对象获取方法

statistics - RavenDB:Raven Query 未返回具有文档授权的正确计数

python - 根据另一个中的值填充新的 pandas df 列

c# - 在EntityContainer中未定义EntitySet。 EF WPF MVVM

C# 单元测试在 Azure DevOps 中运行,但不在 Visual Studio 中运行

MySQL 筛选结果,其中列 = '$'

c# - 添加引用失败。用户取消了保存对话框 (OLE_E_PROMPSAVECANCELLED)

c++ - 以未指定大小、空括号定义的静态数组?