A bad API design in .NET

来源:互联网 发布:厕所没门知乎 编辑:程序博客网 时间:2024/04/29 17:33

ArgumentNullException constructor is really a bad API design sample. First let us review the constructor definition of ArgumentException and ArgumentNullException(From MSDN):

public ArgumentException( string message, string paramName )

public ArgumentNullException( string paramName, string message )

As we know ArgumentNullException is the derived class of ArgumentException, but I don't know why the first param of derived class is paramName wheares base class is different. What's worse is both of params are string type so misunderstanding can't be found by compiler.

This bad design has been existing in all .NET versions(1.0-3.5), so we can conclude that a bad design is not easy to fix especially in case of compatibility is considered.

原创粉丝点击