开发者

equivalent of SQL binary relative value test in C#

I am trying to figure out the equivalent C开发者_JAVA技巧# 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?


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.

if (String.Compare(var1, var2, StringComparison.Ordinal) > 0)
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜