相当于 C# 中的 SQL 二进制相对值测试
我试图找出此 SQL 的等效 C#:
@var1 = "1a1"
@var2 = "1F"
CONVERT(varbinary, @var1) > CONVERT(varbinary, @var2)
它与此相同吗?
if (var1.CompareTo(var2) > 0)
{
}
如果不是,那我该如何模拟呢?
I am trying to figure out the equivalent C# for this SQL:
@var1 = "1a1"
@var2 = "1F"
CONVERT(varbinary, @var1) > CONVERT(varbinary, @var2)
Is it the same as this?
if (var1.CompareTo(var2) > 0)
{
}
If not, then how do I simulate it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
转换为 varbinary 可能是为了强制进行区分大小写的比较。如果这是唯一的问题,那么是的,这两个陈述是等效的。
默认字符串比较区分大小写。但是,默认字符串比较将使用当前区域性信息,并且可能会根据区域性以不同方式处理某些字符串。如果您的应用程序担心这一点,那么您可以使用序数比较,这将产生与 varbinary 强制转换完全相同的结果。
Conversion to varbinary is presumably to force a case-sensitive comparison. If that is the only concern, then yes, the two statements are equivalent.
The default string comparison will be case sensitive. However, the default string comparison will use current culture information and may treat some strings differently depending on culture. If this is a concern for your application, then you can use ordinal comparison instead which would produce exactly the same results a the varbinary cast.