What is this type of Overloading?
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:
10 Replies
Constructor overload?
Where one constructor calls the other
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
it's not a shortcut. it would be impossible to put that into the body
@Ero ? So replacing
with
wouldn't work?
Nope
Oh well - I know I'm fgoing to get a null reference exception
if that's what you're meaning?
You just can't call a constructor from within a constructor, it can only be called with
new
and with the : this(<args>)
notationah! 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
I don't know of a resource for all idiosyncracies but you can read up on constructor chaining in C#
Ha! and that answers the original question. "Constructor Chaining" Thanks again.