相关疑难解决方法(0)

Action,Func和Predicate委托 - C#

我试图理解Action<T>, Func<T> and Predicate<T>代表之间的差异,作为我的WPF/MVVM学习的一部分.

我知道Action<T> and Func<T>两个都是零到一个+参数,只Func<T>返回一个值,而Action<T>不是.

至于Predicate<T>- 我不知道.

因此,我提出了以下问题:

  1. 怎么Predicate<T>办?(欢迎举例!)
  2. 如果什么都不Action<T>返回,那么使用它会不会更简单?(或任何其他类型,如果我们正在讨论.)voidFunc<T>

我希望你在问题中避免使用LINQ/List示例.
我已经看过那些了但是它们只是让它变得更加混乱,因为让我对这些代表"感兴趣"的代码与它无关(我想!).
因此,我想使用我熟悉的代码来获得我的答案.

这里是:

public class RelayCommand : ICommand
{
    readonly Action<object> _execute;
    readonly Predicate<object> _canExecute;

public RelayCommand(Action<object> execute)
    : this(execute, null)
{
}

public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
    if (execute == null)
        throw new ArgumentNullException("execute");

    _execute = execute;
    _canExecute = canExecute;
}

[DebuggerStepThrough]
public bool CanExecute(object parameters)
{
    return …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf delegates mvvm

5
推荐指数
1
解决办法
6783
查看次数

标签 统计

.net ×1

c# ×1

delegates ×1

mvvm ×1

wpf ×1