试图将JS &&运算符转换为C#

我有要转换为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 */


守候你守候我
浏览 110回答 1
1回答

明月笑刀无情

(t = t - c + e) 要求前三个条件为真。public int Rir(int t, int e, int c, int n){&nbsp; &nbsp; if (t > e && t <= c)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; t += (n % (c - e));&nbsp; &nbsp; &nbsp; &nbsp; if (t > c)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = ((t - c) + e);&nbsp; &nbsp; }&nbsp; &nbsp; return t;}
打开App,查看更多内容
随时随地看视频慕课网APP