c# - String.Equals 和运算符 == 之间的无限调用循环

标签 c# .net string

我的一个 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/

相关文章:

c# - 从网络服务器使用 MySQL 的 Windows 应用程序

c# - 使用反射检测属性上的访问修饰符类型

c# - 在 .Net/C# 中,null 是强类型的吗?

c# - 如何在给定负载下运行 CPU(CPU 利用率百分比)?

c# - 动态调用类方法

c# - 在使用javascript上传之前检查图像的宽度和高度?

c# - Excel 进程仍在后台运行

jquery - 追加 JSON 字符串

java - 在一行中仅打印字符串的前 5 个字符

c# - String.Empty 不是 Const 有什么具体原因吗?