我刚刚在.NET基础库的反射器中发现了这段代码...
if (this._PasswordStrengthRegularExpression != null)
{
this._PasswordStrengthRegularExpression = this._PasswordStrengthRegularExpression.Trim();
if (this._PasswordStrengthRegularExpression.Length == 0)
{
goto Label_016C;
}
try
{
new Regex(this._PasswordStrengthRegularExpression);
goto Label_016C;
}
catch (ArgumentException exception)
{
throw new ProviderException(exception.Message, exception);
}
}
this._PasswordStrengthRegularExpression = string.Empty;
Label_016C:
... //Other stuff
我听过所有的“你不应该使用goto,否则你将被永远流放到地狱”的说法。我一直很尊重微软的编码人员,虽然我可能不同意他们的决定,但我总是尊重他们的理由。
那么,这种代码存在什么好的理由是我忽略了的吗?这段代码是不是由一个无能的开发者拼凑起来的?还是.NET反编译器返回了不准确的代码?
我希望有个好的理由存在,而我只是盲目地错过了它。
感谢大家的意见。
GOTO
语句都应该与描述性的标签配对,比如OVER_THERE
(那边)、HELL
(地狱)、JAIL
(监狱)和BED
(床)。 - Armstrongest