试图转换JS&& C#的运算符函数

时间:2018-04-26 03:08:56

标签: javascript c#

我有JS代码,我试图转换为C#。出于某种原因,我的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#Method&amp;用法:

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 个答案:

答案 0 :(得分:2)

var gAssembly = Assembly.LoadFrom(JLDBConnection.Properties.Settings.Default.DefaultString + @"\JLRetailTerminal.exe"); Type typ = gAssembly.GetExportedTypes().Where(s => s.Name == "RetailWindow").FirstOrDefault(); //if extend sale is set prevent multiple windows if (gWindow == null) {//show if window has never been opened gWindow = (Window)Activator.CreateInstance(typ); gWindow.Show(); } else {//window has been opened var windows = Application.Current.Windows; //get all opened windows in applications if (!windows.OfType<Window>().Contains(gWindow) || !(JLDBConnection.Properties.Settings.Default.ExtendSale == "Yes")) { //if window has been closed or not multiple sale database gWindow = (Window)Activator.CreateInstance(typ); gWindow.Show(); } } 要求前三个条件为真。

(t = t - c + e)