I am having difficulty with the strict typing in C# when it comes to function arguments.
For my Reverse Polish Notation (RPN) calculator, the required arguments will be passed through a function call using a comma-separated list of different types:
this.FxMath.RPN(this.Mt, this.L, 2, '*', this.F, '*') // (this.Mt are Variables as Objects)
The function itself will receive the comma-separated arguments as ...seq:
RPN(ergebnis: VariableUnitBuilder, ...seq: any) {
like this:
RPN(ergebnis: VariableUnitBuilder, ...seq: any) {
let stack = [], i = 0;
typeof seq[i] === 'object' ? seq[i] = seq[i].nominalValue : null;
stack.push(seq[i]);
i++;
while (i <= seq.length) {
typeof seq[i] === 'object' ? seq[i] = seq[i].nominalValue : null; // Extract number value or do nothing.
let item = seq[i]; // Number or operator
if (isNaN(item)) {
let a: number;
let b: number;
switch (item) {
case '+':
a = parseFloat(stack.pop());
b = parseFloat(stack.pop());
stack.push(a + b);
break;
...... }
Now I need some arguments with different types and an unknown length:
(this.Mt, this.L, 2.5, '*', this.F, '*') // Class, Class, Double , String, Class, String