我不知道如何根据我将在运行时传入的值在我拥有的列表上进行“查找”。如果您看到我下面的代码,我希望能够在 List 中找到其 Path 参数等于 X 的 CustomClass,其中 X 将在运行时定义。
任何想法如何在列表中进行此类查找?或者如果不编写迭代器并手动进行查找,这是不可能的吗?在这种情况下,也许我应该考虑使用一个带键的集合?
private List<CustomClass> files;
public void someMethod()
{
Uri u= new Uri(www.test.com);
CustomClass cc = this.files.find( matchesUri(u) ); // WON'T LET ME DO THIS
}
private static bool matchesUri(List<CustomClass> cc, Uri _u)
{
return cc.Path == _u; }
public class CustomClass
{
private Uri path;
public Uri Path
{
get { return this.path; }
set { this.path = value; }
}
}
PS。我必须承认我不太了解http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx上的 doco 中的谓词内容