我的一个 friend 偶然发现了 String.cs 中这两个方法的有趣源代码:
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool operator ==(string a, string b)
{
return Equals(a, b);
}
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool Equals(string a, string b)
{
return ((a == b) || (((a != null) && (b != null)) && EqualsHelper(a, b)));
}
为什么它不会导致无限循环? (我们所有的程序都将被 StackOverflowException 终止!)
最佳答案
显然是这样,至少根据公认的答案是这样。
(在我有一定数量的代表之前我不能发表评论。Hooray SO。)
关于c# - String.Equals 和运算符 == 之间的无限调用循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10925217/