コード例 #1
0
    // A utility method to apply an operator 'op' on operands 'a'
    // and 'b'. Return the result.
    public static long DoOperation(string op, long b, long a)
    {
        checked
        {
            switch (op)
            {
            case "+":
                return(a + b);

            case "-":
                return(a - b);

            case "*":
                return(a * b);

            case "/":
                return(a / b);

            case "%":
                return(a % b);

            case "&":
                return(a & b);

            case "^":
                return(a ^ b);

            case "|":
                return(a | b);

            case ">>":
                return(Convert.ToInt64(Bitwise.Rsh(a.ToString(), b.ToString())));

            case "<<":
                return(Convert.ToInt64(Bitwise.Lsh(a.ToString(), b.ToString())));
            }
        }
        return(0);
    }