"on String 就像在 Powershell 中一样?-6ren"> "on String 就像在 Powershell 中一样?-在 PowerShell 中我可以比较 2 个字符串: "002" -gt "001" 在 C# 中,我不能对字符串使用“>”。那么有什么选择呢? 最佳答案 您可以使用 String.Compa-6ren">
gpt4 book ai didi

c# - 在 C# 中替代 ">"on String 就像在 Powershell 中一样?

转载 作者:太空宇宙 更新时间:2023-11-03 19:56:36 24 4
gpt4 key购买 nike

在 PowerShell 中我可以比较 2 个字符串:

   "002" -gt "001"

在 C# 中,我不能对字符串使用“>”。那么有什么选择呢?

最佳答案

您可以使用 String.Compare

String.Compare("002", "001", StringComparison.Ordinal)

最好使用需要 StringComparison 的重载之一参数:

When you call a string comparison method such as String.Compare, String.Equals, or String.IndexOf, you should always call an overload that includes a parameter of type StringComparison so that you can specify the type of comparison that the method performs. For more information, see Best Practices for Using Strings in the .NET Framework.

关于c# - 在 C# 中替代 ">"on String 就像在 Powershell 中一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com