C# 和委托(delegate)

标签 c# delegates

我想使用一个委托(delegate),它允许我使用 FIND 搜索列表中的一个项目与另一个列表中的另一个项目的匹配。

我的代码工作如下: -

Type a = listname.Find(delegate(Type b))
{
         return list.item == b.list.item;
}

如果列表项与 b 中的项匹配,则返回 a 中的项。这工作正常,但是我现在想检查是否只返回 a 如果 list.item 中有多个项目与 b.list.item 匹配,例如
Type a = listname.Find(delegate(Type b))
{
         return list.item == b.list.item;
                 list.anotheritem == b.list.anotheritem
}

我似乎无法对其进行编码,以便在返回 Type a 之前检查多个条件。

最佳答案

Type a = listname.Find(delegate(Type b) 
{ 
         return list.item == b.list.item &&
                 list.anotheritem == b.list.anotheritem;
} 

关于C# 和委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7941065/

相关文章:

c# - InternalsVisibleTo 导致 CS0246 错误 : The Type or Namespace could not be found

c# - ASP.NET 委托(delegate)和表达式 - 信息请求

ios - 如何缩小 iOS 中的 View Controller ?

c# - 检查委托(delegate)是否是对象的方法,并检索该对象引用和方法名称

c# - 如何使用asp.net c#根据用户输入查询oracle数据库

c# - 更改类对象列表中项目值的正确方法

c# - 无法初始化模拟类的成员

c# - Visual Studio 单元测试代码覆盖异常 "file path of .coverage file is invalid or corrupt"

c# - delegate.Invoke 是如何工作的?

c# - 将 lambda 作为委托(delegate)传递给方法