我的基类中有以下两个构造函数:
protected ExternalSystemException( params Object[] args )
: this( null, null, args ) {}
protected ExternalSystemException( String propertyKeySuffix,
params Object[] args ) : this( propertyKeySuffix, null, args ) {}
Run Code Online (Sandbox Code Playgroud)
我的子类有以下构造函数:
public InvalidPathToOutputFiles(string invalidPath)
: base(invalidPath) {}
Run Code Online (Sandbox Code Playgroud)
我的客户端逻辑实例化子类,如下所示:
throw new ChildClass( "goofy" );
Run Code Online (Sandbox Code Playgroud)
当我逐步完成逻辑时,我意外地在参数的基础构造函数中结束( String propertyKeySuffix, params Object[] args ).我期望调用其他基类构造函数,即( params Object[] args ).
有人能告诉我为什么会这样吗?
该string超负荷是你提供给构造函数的类型的最佳匹配.Params是可选的(并且Object是不明确的),因此第二个重载的string类型与string您传递的类型相匹配,所以选择了第二个重载.
| 归档时间: |
|
| 查看次数: |
146 次 |
| 最近记录: |