← Back to Projects
Web-Based Calculator
A calculator built three ways — PHP+C#, WPF, and Next.js.
0
Three Implementations
PHP + C# Console
PHP / C#The PHP frontend builds the expression string and calls PHP's system() to spawn a compiled C# .exe as a subprocess. The .exe evaluates the expression using ADO.NET's DataTable column expression parser — a rarely-seen trick that turns SQL expression evaluation into a math engine.
// PHP (jQuery) — build expression and POST to backend
$.post("index.php", { var_value: path + " " + field.text() });
// PHP backend — execute the compiled C# .exe as a subprocess
$result = system($_POST['var_value']);
// C# — evaluate the expression using ADO.NET's DataTable parser
public static double Evaluate(string expression)
{
DataTable table = new DataTable();
table.Columns.Add("expression", typeof(string), expression);
DataRow row = table.NewRow();
table.Rows.Add(row);
return double.Parse((string)row["expression"]);
}WPF Desktop
C# / WPFThe Windows Presentation Foundation version uses INotifyPropertyChanged for two-way data binding between the button grid and the display label — the same MVVM binding pattern used in enterprise .NET desktop applications.
public string LabelText
{
get { return labelText; }
set
{
labelText = value;
RaisePropertyChanged("LabelText");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}Next.js
TypeScript / ReactThis demo reimplements the same calculator as a React client component, evaluating the expression with JavaScript's Function constructor in a try/catch to safely handle invalid input.
function evaluate(expr: string): string {
try {
const result = Function('return ' + expr)()
return String(result)
} catch {
return 'Error'
}
}