Introduction

Problem

You need to evaluate an arithmetic/mathematic dynamic expression at runtime.

Solution

The Eval-Expression.NET can evaluate all C# code dynamically including arithmetic/mathematic.

Everything is supported

  • Operator Precedence
  • Operator Associativity
  • ‘+’, ‘-‘, ‘*’, ‘/’
  • ‘^^’ (Power Operator)
  • Etc.

Example – Simple mathematic expression

// using Z.Expressions; // Don't forget to include this.

var result = Eval.Execute("2+3*4"); // return 16;

Example – Expression with ‘Power’ operator

// using Z.Expressions; // Don't forget to include this.

var result = Eval.Execute("2^^3"); // return 8;

Example – Expression with Parameter

// using Z.Expressions; // Don't forget to include this.

var result = Eval.Execute("X^^Y", new { X = 2, Y = 3 }); // return 8;