在 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/