|
using System;
using System.Collections.Generic;
using System.Text;
namespace SevenZ.Calculator
{
public partial class Calculator
{
public delegate void CalcVariableDelegate(object sender, EventArgs e);
public event CalcVariableDelegate OnVariableStore;
Dictionary<string, double> variables;
public const string AnswerVar = "r";
private void LoadConstants()
{
variables = new Dictionary<string, double>();
variables.Add("pi", Math.PI);
variables.Add("e", Math.E);
variables.Add(AnswerVar, 0);
if (OnVariableStore != null)
OnVariableStore(this, new EventArgs());
}
public Dictionary<string, double> Variables
{
get { return variables; }
}
public void SetVariable(string name, double val)
{
if (variables.ContainsKey(name))
variables[name] = val;
else
variables.Add(name, val);
if (OnVariableStore != null)
OnVariableStore(this, new EventArgs());
}
public double GetVariable(string name)
{ // return variable's value // if variable ha push default value, 0
return variables.ContainsKey(name) ? variables[name] : 0;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a Master degree student, studying at the University of Joensuu, Finland.