C#初学者:我的IList.Where()方法在哪里去了? [英] C# Beginner: Where has my IList.Where() method gone?
问题描述
我有另一个简单的一个(我想),这是骗我。我已经写了一个方法在我的控制之一,获取CMS中的文件的最新版本,给定它的文件名(即,不管文件驻留在什么文件夹)。我发现它有用,我想我会在我的CMSToolbox类中,但是当我这样做,我不能再使用FileManager类的 Where()
方法
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提供的类扩展 Control
)我可以访问< c $ c> Where()方法,但在我的ToolBox类中我不。是什么赋予了?我认为 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.
a wrong again,haha:)
I'm a wrong again, haha :)
编辑: Filemanager.GetGroupAll $ c>返回一个
CMSList
,它扩展了 IList
推荐答案
您需要一个使用指令 System.Linq
。 .Where()
是 IEnumerable< T>
(其中 IList< T& ;
implements)在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屋!