将 javascript 方法的功能转换为 C#
我有一个 javascript 函数,它具有我想要转换为 C# 的功能。我不知道如何正确翻译这个。
有人可以帮忙吗?
function validateSequenceNumber(val, num) {
var seqNumber = ((parseFloat(num) + 0xCED9) * 0x8088405) & 0xFFFF
var checksum = seqNumber.toString(16).toUpperCase()
if (checksum != val.substring(11, 15)) {
return false;
}
return true;
}
I have a javascript function that has functionality that I would like to convert to C#. I'm not sure how to properly translate this.
Can anyone help?
function validateSequenceNumber(val, num) {
var seqNumber = ((parseFloat(num) + 0xCED9) * 0x8088405) & 0xFFFF
var checksum = seqNumber.toString(16).toUpperCase()
if (checksum != val.substring(11, 15)) {
return false;
}
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
parseFloat
变为float.Parse
,seqNumber.toString(16)
变为string.Format("{0:x}", seqNumber ).ToUpper();
另外注意C#中的子串参数不是start、end;而是开始,长度。所以要小心。
function
显然变成了bool
。我想就是这样。parseFloat
becomesfloat.Parse
,seqNumber.toString(16)
becomesstring.Format("{0:x}", seqNumber).ToUpper();
And note on substring parameters in C# are not start, end; rather start, length. So be careful.
function
becomesbool
obviously. And I think that's it.使用的字符串函数还应该使用不变区域性,因为该函数似乎不用于文本显示。以下是函数的转换方式:
编辑:添加了 Unchecked 关键字:将发生的溢出错误在这里似乎并不重要。
The string functions used should also use the invariant culture, since the function doesn't appear to be used for text display. Below is how the function might be converted:
EDIT: Added Unchecked keyword: the overflow errors that would occur appear to be unimportant here.