【发布时间】:2011-12-16 09:36:30
【问题描述】:
假设如果我们尝试将 null 分配给某个东西,我们想抛出,那么这个技巧呢:
public static class ExceptionExtension
{
public static T Throw<T>(this Exception exc)
{
throw exc;
}
}
我们可以像这样使用:
return possibleNull ?? new Exception("Unspecified something....").Throw<string>();
您认为这是一种好/最差/无用的做法吗?
【问题讨论】:
标签: c# syntactic-sugar