I have the following two constructors in my base class:
prote开发者_开发技巧cted ExternalSystemException( params Object[] args )
: this( null, null, args ) {}
protected ExternalSystemException( String propertyKeySuffix,
params Object[] args ) : this( propertyKeySuffix, null, args ) {}
My child class has the following constructor:
public InvalidPathToOutputFiles(string invalidPath)
: base(invalidPath) {}
My client logic instantiates the child class like so:
throw new ChildClass( "goofy" );
When I step through the logic I unexpectedly end up at the base constructor with the parameters ( String propertyKeySuffix, params Object[] args )
. I expected the other base class constructor to be called, namely ( params Object[] args )
.
Can someone tell me why this is happening?
The string
overload is the best match to the type you are providing to the constructor. The Params are optional (and Object is ambiguous), so since the second overload has a string
type that matches the string
type you are passing, the second overload is selected.
精彩评论