Why do I need getters and setters in ICommand? : <p>New to C#/MVVM and this doesn't make sense to me?</p>

<p>This is my implementation of a RelayCommand inheriting from ICommand:</p>

<pre><code>internal class RelayCommand : ICommand
{
    private readonly Predicate&lt;object&gt; _canExecute;
    private readonly Action _execute;
    public event EventHandler CanExecuteChanged = (sender, e) =&gt; {};

    public RelayCommand(Action execute) : this(execute, null){ }
    public RelayCommand(Action execute, Predicate&lt;object&gt; canExecute)
    {
        _execute = execute;
        _canExecute = canExecute;
    }

    public bool CanExecute(object parameter) =&gt; (_canExecute == null) ? true : _canExecute(parameter);

    public void Execute(object parameter) =&gt; _execute();
}
</code></pre>

<p>I found out through testing that I simply can't just do this:</p>

<pre><code>public RelayCommand TestCommand;
</code></pre>

<p>I have to do this:</p>

<pre><code>public RelayCommand TestCommand { get; set; }
</code></pre>

<p>Otherwise declaring the command in the constructor like this:</p>

<pre><code>TestCommand = new RelayCommand(TestCommandFunction);

public void TestCommandFunction(){}
</code></pre>

<p>won't work. Why is this the case?</p>
