我有要轉(zhuǎn)換為C#的JS代碼。由于某種原因,我的C#方法返回的值比JS函數(shù)的返回值小10。我嘗試更改多個(gè)內(nèi)容并檢查&&JS中運(yùn)算符的含義,但似乎無法弄清楚我在做什么錯(cuò)。正確的返回值為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貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
(t = t - c + e) 要求前三個(gè)條件為真。
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 關(guān)注
- 131 瀏覽
添加回答
舉報(bào)
0/150
提交
取消