C # formula calculation (string ),
1) Call JS computing methods (not recommended, low efficiency)
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();scriptControl.Language = "JScript";string value = scriptControl.Eval("1+2*(4-3)").ToString();Console.WriteLine(value);
2) use the Compute () method of DataTable
DataTable table = new DataTable();string value = table.Compute("1+2*(4-3)", "").ToString();Console.WriteLine(value);
3) construct a able and add a formula to the column name
// Formula string expression1 = "a + B * (c-d)"; string expression2 = "a + B-c-d "; // construct tableDataTable table = new DataTable (); table. columns. add ("a", typeof (int); table. columns. add ("B", typeof (int); table. columns. add ("c", typeof (int); table. columns. add ("d", typeof (int); table. columns. add ("e1", typeof (int); // formula column table. columns. add ("e2", typeof (int); // formula column // Add formula table. columns ["e1"]. expression = expression1; table. columns ["e2"]. expression = expression2; // Add a row and assign the value DataRow row = table. rows. add (); row ["a"] = 1; row ["B"] = 2; row ["c"] = 4; row ["d"] = 3; table. beginLoadData (); table. endLoadData (); for (int I = 0; I <table. columns. count; I ++) {Console. write (table. columns [I]. columnName + "\ t");} Console. writeLine (); for (int I = 0; I <table. columns. count; I ++) {Console. write (row [I]. toString () + "\ t ");}
C language ^ how to use
A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010
B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011
^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.
//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].
C language ^ how to use
A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010
B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011
^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.
//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].