【发布时间】:2011-10-30 11:32:17
【问题描述】:
为什么ThrowIfNull 实现为:
static void ThrowIfNull<T>(this T argument, string name) where T : class
{
if (argument == null)
{
throw new ArgumentNullException(name);
}
}
改写成这样是不是更好:
static void ThrowIfNull<T>(this T argument, string name) where T : class
{
if (object.ReferenceEquals(argument, null))
{
throw new ArgumentNullException(name);
}
}
优点:它有助于避免混淆 Equals 重载,并可能使代码更清晰。
这样做有什么缺点吗?应该有的。
【问题讨论】: