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

标签 c# powershell

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

相关文章:

c# - 如何使用 HttpGet 将对象作为参数传递给 Web API

c# - 使用外键链接的集合保存实体时出现 EF 错误

powershell - 如何在 Ubuntu 18.04 上将 Powershell Core 更新到最新版本

powershell - Terraform GCP 无法为 Windows 实例运行元数据命令来创建用户

c# - Button Style 的内容只出现在一个 Button 实例中

c# - excel中的键盘快捷键csv文件列标题宽度自动调整

powershell - 返回正确的 .length 即使长度为 1

Powershell - 从特定字符捕获 var 中的文本

azure - 有没有更好的方法来获取 Graph API Powershell 中特定 MemberOf 组的用户信息及其经理

c# - 对象列表中对象参数的最大值