uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
DataType = [DataType]
Property
Product:
Class:
Retrieves the resulting data type of a parsed expression without needing to evaluate it.
Remarks
🎯 Retrieving Expression Types
The DataType method is an introspection tool that returns the resulting DataType of a parsed expression without actually evaluating it. This allows you to inspect the type of an expression before execution, enabling powerful features like static analysis, type validation, and conditional logic based on the expected output.
⚙️ How Type is Determined
When an expression is parsed, its final return type is determined by a clear hierarchy:
- Explicit
ReturnType: If aDataTypewas provided in the Parse() call (e.g.,uc.Parse("1+2", uc.DataTypeOf("String"))), that type is used. - Inference from Expression: uCalc analyzes the last operation in the expression. The return type of that function or operator becomes the return type of the entire expression. For example:
1 > 2results inBoolean.'a' + 'b'results inString.1 + 2 * #iresults inComplex.1.5 * 2results inDouble.
- Fallback to Default: If the type cannot be inferred (e.g., a variable-only expression without an explicit type), the engine uses the instance's DefaultDataType, which is
Doubleby default.
🤔 Why is this useful? (Comparative Analysis)
In statically typed languages like C#, typeof(int) gets a type at compile time, and myObject.GetType() gets an object's type at runtime after it has been created. uCalc's DataType method offers a different paradigm: it determines the type of a potential result from its unevaluated definition.
Without uCalc: You would have to parse the string yourself or evaluate it and then check the type of the result, which could be slow or trigger unwanted errors (like division by zero).
With uCalc: You can safely inspect the type first. This is crucial for:
- Building a typed scripting language: A host application can validate that a user's script will return a
Booleanfor anifcondition before running it. - Dynamic UI: A report generator can check if an expression returns a
Stringor aNumberand choose the appropriate display control (e.g., a label vs. a chart). - Preventing runtime errors: Check the types of arguments being passed to a function before calling it.
- Building a typed scripting language: A host application can validate that a user's script will return a
Examples
Displaying the data type of a parsed expression
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name);
Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name);
Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name);
Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name);
double
string
complex
bool using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name); Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name); Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name); Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.Parse(" 3 + 6 * 10 ").DataType().Name() << endl;
cout << uc.Parse(" 'This ' + 'is a string' ").DataType().Name() << endl;
cout << uc.Parse(" 2 + 8 * #i / 2").DataType().Name() << endl;
cout << uc.Parse(" 10 + 2 > 3").DataType().Name() << endl;
}
double
string
complex
bool #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.Parse(" 3 + 6 * 10 ").DataType().Name() << endl; cout << uc.Parse(" 'This ' + 'is a string' ").DataType().Name() << endl; cout << uc.Parse(" 2 + 8 * #i / 2").DataType().Name() << endl; cout << uc.Parse(" 10 + 2 > 3").DataType().Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name)
Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name)
Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name)
Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name)
End Sub
End Module
double
string
complex
bool Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.Parse(" 3 + 6 * 10 ").DataType.Name) Console.WriteLine(uc.Parse(" 'This ' + 'is a string' ").DataType.Name) Console.WriteLine(uc.Parse(" 2 + 8 * #i / 2").DataType.Name) Console.WriteLine(uc.Parse(" 10 + 2 > 3").DataType.Name) End Sub End Module