A 'Hello, World!' example demonstrating the creation and evaluation of an expression using the modern, simplified syntax.

ID: 1176

				
					using uCalcSoftware;

var uc = new uCalc();
// Create a new Expression object with an initial formula.
// This uses the default uCalc instance for context.
var expr = new uCalc.Expression("1 + 1");

// Implicitly calls .EvaluateStr() when used in a string context
Console.WriteLine($"Initial value: {expr}");

// Reassign the expression to a new formula with a simple string assignment.
// This implicitly calls .Parse() behind the scenes.
expr = "10 * (5 + 3)";

// expr.Evaluate() is implicitely called.
Console.Write("New value: "); Console.Write(expr);
				
			
Initial value: 2
New value: 80
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Create a new Expression object with an initial formula.
   // This uses the default uCalc instance for context.
   uCalc::Expression expr("1 + 1");

   // Implicitly calls .EvaluateStr() when used in a string context
   cout << "Initial value: " << expr << endl;

   // Reassign the expression to a new formula with a simple string assignment.
   // This implicitly calls .Parse() behind the scenes.
   expr = "10 * (5 + 3)";

   // expr.Evaluate() is implicitely called.
   cout << "New value: " << expr;
}
				
			
Initial value: 2
New value: 80
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Create a new Expression object with an initial formula.
      '// This uses the default uCalc instance for context.
      Dim expr As New uCalc.Expression("1 + 1")
      
      '// Implicitly calls .EvaluateStr() when used in a string context
      Console.WriteLine($"Initial value: {expr}")
      
      '// Reassign the expression to a new formula with a simple string assignment.
      '// This implicitly calls .Parse() behind the scenes.
      expr = "10 * (5 + 3)"
      
      '// expr.Evaluate() is implicitely called.
      Console.Write("New value: ")
      Console.Write(expr)
   End Sub
End Module
				
			
Initial value: 2
New value: 80