我有要转换为C#的JS代码。由于某种原因,我的C#方法返回的值比JS函数的返回值小10。我尝试更改多个内容并检查&&JS中运算符的含义,但似乎无法弄清楚我在做什么错。正确的返回值为97。JavaScript功能和用法:function rir(t, e, c, n) { return t > e && t <= c && (t += n % (c - e)) > c && (t = t - c + e), t}rir('a'.charCodeAt(0), 47, 57, 'b'.charCodeAt(0));/* returns 97 */C#方法和用法:public int Rir(int t, int e, int c, int n){ if (t > e && t <= c) t += (n % (c - e)); if (t > c) t = ((t - c) + e); return t;}Rir((int)'a', 47, 57, (int)'b');/* returns 87 */
1 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
(t = t - c + e) 要求前三个条件为真。
public int Rir(int t, int e, int c, int n)
{
if (t > e && t <= c)
{
t += (n % (c - e));
if (t > c)
t = ((t - c) + e);
}
return t;
}
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报
0/150
提交
取消