我有一个方法,它将一个委托作为参数(比如说动作),将其设置为null。当我使用参数调用该方法时,我需要通过调用该委托从列表中选择与该委托匹配的元素。当我没有传递委托作为参数时,它需要考虑该列表的所有元素。
public List<Reducere> Reduceri { get; set; }
public void AplicaReduceri(Func<Reducere, string> selector = null)
{
if (selector != null)
{
//here I need to select a Reducere from the list
//that matches that delegate by invoking the delegate
}
else
{
//here I need to take in consideration all the elements of that list
}
}