C# EndsWith 有时会给出错误的结果

问题描述

"Cs".EndsWith("s") 和 "cs".EndsWith("s") 给我“假”。

我整理了一个简单的控制台应用程序来解决这个问题:

string[] strings = { "s","As","Bs","Cs","Ds","Es","as","bs","cs","ds","es","AAs","ABs","ACs","ADs","AEs" };
foreach (string str in strings)
  Console.WriteLine(str + " ends with 's': " + str.EndsWith("s"));
Console.ReadKey();

结果如下:

s ends with 's': True
As ends with 's': True
Bs ends with 's': True
Cs ends with 's': False
Ds ends with 's': True
Es ends with 's': True
as ends with 's': True
bs ends with 's': True
cs ends with 's': False
ds ends with 's': True
es ends with 's': True
AAs ends with 's': True
ABs ends with 's': True
ACs ends with 's': False
ADs ends with 's': True
AEs ends with 's': True

我尝试更改目标框架:(VS2013)

  • 所有 4.x 版本都产生了这个错误
  • 在 .NET 3.5、3.0、2.0 上运行良好。

还尝试使用 .NET 6.0 使用 VS2022 Preview(在 2 台不同的计算机上),但产生了相同的问题。

在 dotnetfiddle (.NET 4.7.2) 中运行良好... :-O

你能帮我在哪里寻找解决方案吗? (设置、安装的软件等)

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)