when I doing a coding I come across a function like this =>
public RelayCommand(Action<object> execute): this(execute, null)
I really dont know about the "this" key word usage here
when I doing a coding I come across a function like this =>
public RelayCommand(Action<object> execute): this(execute, null)
I really dont know about the "this" key word usage here
It's constructor chaining. this(execute, null)
calls another constructor defined in that class which takes an Action<object>
and some other value. For example:
class Whatever
{
public Whatever() : this("string arg") {} // calls Whatever(string)
public Whatever(string something) {}
}
This particular use of this
keyword lets you call one constructor from the other, presumably to supply a default argument. You can "fold" both constructors into one by applying default parameter values:
public RelayCommand(Action<object> execute, string name = null) {
...
}
This is referring to an overloaded version of the current constructor. Basically the two constructors are chained together which can be good for avoiding duplicate code in constructors