using uCalcSoftware; var uc = new uCalc(); // Original default instance uCalc.DefaultInstance.DefineVariable("id = 'Original'"); Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}"); // Push a new default instance onto the stack var ucA = new uCalc(); ucA.DefineVariable("id = 'Instance A'"); ucA.IsDefault = true; Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}"); // The 'NewUsing' block creates a temporary, scoped default instance // The following instance will be auto-released at the end of the block using (var ucB = new uCalc()) { ucB.DefineVariable("id = 'Instance B (temp)'"); ucB.IsDefault = true; // Pushes 'ucB' onto the stack Console.WriteLine($"Current Default ID: {uCalc.DefaultInstance.EvalStr("id")}"); } // 'ucB' has gone out of scope, so the default reverts to the previous one ('ucA') Console.WriteLine($"Current Default ID (after scope exit): {uCalc.DefaultInstance.EvalStr("id")}"); // Manually unset 'ucA' ucA.IsDefault = false; Console.WriteLine($"Current Default ID (after unset): {uCalc.DefaultInstance.EvalStr("id")}");