C#初学者:我的IList.Where()方法在哪里去了? [英] C# Beginner: Where has my IList.Where() method gone?

查看:1571
本文介绍了C#初学者:我的IList.Where()方法在哪里去了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有另一个简单的(我认为)这就是两腿发僵我。我在我的控制之一,获取最新版本的文件在CMS给它的文件名写的方法(即无论文件驻留在什么文件夹中)。我发现它足够有用,我想我不干了,我CMSToolbox类,但我这样做的时候,我可以不再使用其中() A文件管理类的方法。由CMS(返回一个列表)提供

I've got another simple one (I think) that's stumping me. I have written a method in one of my controls that gets the latest version of a file in a CMS given it's filename (i.e. regardless of what folder the file resides in). I found it useful enough that I thought I'd chuck it in my CMSToolbox class, but when I do this I can no longer use the Where() method of a FileManager class provided by the CMS (which returns a list).

下面是我班的一个简单的例子:

Here's a simplified example of my 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提供了一个类控制)我有机会获得其中()方法,但在我的工具箱类我不知道。是什么赋予了?我想,一个的IList 总是让您从任何地方使用它访问相同的方法。

When I do exactly the same thing in the context of a Control (really a class provided by the CMS which extends Control) I have access to the Where() method, but in my ToolBox class I don't. What gives? I figured that an IList would always allow access to the same methods from wherever you use it.

我一个又错了,哈哈:)

I'm a wrong again, haha :)


编辑:文件管理器。 GetGroupAll()返回 CMSList 延伸的IList

推荐答案

您需要一个using指令 System.Linq的。凡()的IEnumerable℃的扩展方法; T> (其中的IList< T> ; 实现),它在System.Linq的命名空间中定义

You need a using directive for System.Linq. .Where() is an extension method on IEnumerable<T> (which IList<T> implements) that is defined in the System.Linq namespace.

这篇关于C#初学者:我的IList.Where()方法在哪里去了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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