C
Join ServerC#
help
What is this type of Overloading?
Sstigzler10/22/2022
I'm converting from vb to c#. What's the correct term for the line
public RelayCommand(Action<object> execute) : this(execute, null)
in this overloading? It's very helpful:public class RelayCommand : ICommand
{
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
public RelayCommand(Action<object> execute) : this(execute, null)
{
}
}
TTvde110/22/2022
Constructor overload?
TTvde110/22/2022
Where one constructor calls the other
Sstigzler10/22/2022
hey, thanks for the response. It was more the c# shortcut - i.e. putting the
: this(execute,null)
on the end, rather than typing RelayCommand(execute, null)
in the method body. Having thought about it, maybe it doesn't have a name. I just need to find all these handy c# shortcuts. I thought it might have one as it's similar to the syntax for Inherits where you put a colon after the Class name e.g. : INotifyPropertyChanged
EEro10/22/2022
it's not a shortcut. it would be impossible to put that into the body
Sstigzler10/22/2022
@Ero ? So replacing
with
wouldn't work?
public RelayCommand(Action<object> execute) : this(execute, null)
{
}
with
public RelayCommand(Action<object> execute)
{
RelayCommand(execute, null);
}
wouldn't work?
DDoktor910/22/2022
Nope
Sstigzler10/22/2022
Oh well - I know I'm fgoing to get a null reference exception
Sstigzler10/22/2022
if that's what you're meaning?
DDoktor910/22/2022
You just can't call a constructor from within a constructor, it can only be called with
new
and with the : this(<args>)
notationSstigzler10/22/2022
ah! Well that I would never have known! Thanks a bunch. What's the best reference for all these types of c# idiosyncrasies? That would have driven me potty if I'd have gotten stuck with that. Is there a site? I've done quite a bit of reading on the basics, but it's stuff like this that's going to catch me out
DDoktor910/22/2022
I don't know of a resource for all idiosyncracies but you can read up on constructor chaining in C#
Sstigzler10/22/2022
Ha! and that answers the original question. "Constructor Chaining" Thanks again.