string.IndexOf get different result in .Net 5
问题 When i run following code in .Net Core 3.1 i get 6 //Net Core 3.1 string s = "Hello\r\nworld!"; int idx = s.IndexOf("\n"); Console.WriteLine(idx); Result 6 but when i run this code in .Net 5 i get different result. why? //NET 5 string s = "Hello\r\nworld!"; int idx = s.IndexOf("\n"); Console.WriteLine(idx); Result -1 回答1: The comments and @Ray's answer contain the reason. And though hacking the .csproj or runtimeconfig.json file may save your day the real solution is to specify the comparison