A minimal example demonstrating the basic 'Parse once, Evaluate many' pattern.
ID: 1192
using uCalcSoftware;
var uc = new uCalc();
// 1. Parse the expression string once to create a reusable object.
//var expr = uc.Parse("5 * 10");
using (var expr = new uCalc.Expression("5 * 10")) {
// 2. Evaluate the pre-parsed object as many times as needed.
Console.WriteLine(expr.Evaluate());
Console.WriteLine(expr.Evaluate());
} // The expression object is automatically released here.
50
50 using uCalcSoftware; var uc = new uCalc(); // 1. Parse the expression string once to create a reusable object. //var expr = uc.Parse("5 * 10"); using (var expr = new uCalc.Expression("5 * 10")) { // 2. Evaluate the pre-parsed object as many times as needed. Console.WriteLine(expr.Evaluate()); Console.WriteLine(expr.Evaluate()); } // The expression object is automatically released here.
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// 1. Parse the expression string once to create a reusable object.
//var expr = uc.Parse("5 * 10");
{
uCalc::Expression expr("5 * 10");
expr.Owned(); // Causes expr to be released when it goes out of scope
// 2. Evaluate the pre-parsed object as many times as needed.
cout << expr.Evaluate() << endl;
cout << expr.Evaluate() << endl;
} // The expression object is automatically released here.
}
50
50 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // 1. Parse the expression string once to create a reusable object. //var expr = uc.Parse("5 * 10"); { uCalc::Expression expr("5 * 10"); expr.Owned(); // Causes expr to be released when it goes out of scope // 2. Evaluate the pre-parsed object as many times as needed. cout << expr.Evaluate() << endl; cout << expr.Evaluate() << endl; } // The expression object is automatically released here. }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// 1. Parse the expression string once to create a reusable object.
'//var expr = uc.Parse("5 * 10");
Using expr As New uCalc.Expression("5 * 10")
'// 2. Evaluate the pre-parsed object as many times as needed.
Console.WriteLine(expr.Evaluate())
Console.WriteLine(expr.Evaluate())
End Using '// The expression object is automatically released here.
End Sub
End Module
50
50 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// 1. Parse the expression string once to create a reusable object. '//var expr = uc.Parse("5 * 10"); Using expr As New uCalc.Expression("5 * 10") '// 2. Evaluate the pre-parsed object as many times as needed. Console.WriteLine(expr.Evaluate()) Console.WriteLine(expr.Evaluate()) End Using '// The expression object is automatically released here. End Sub End Module