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)";

// Retrieve the result. For numeric results, you can assign it
// directly to a double. This implicitly calls .Evaluate().
double result = expr;
Console.Write("New value: "); Console.Write(result);
				
			
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)";

   // Retrieve the result. For numeric results, you can assign it
   // directly to a double. This implicitly calls .Evaluate().
   double result = expr;
   cout << "New value: " << result;
}
				
			
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)"
      
      '// Retrieve the result. For numeric results, you can assign it
      '// directly to a double. This implicitly calls .Evaluate().
      Dim result As Double = expr
      Console.Write("New value: ")
      Console.Write(result)
   End Sub
End Module
				
			
Initial value: 2
New value: 80