//This app shows how to create/use a custom method that returns an answer
//'*************************************USING CUSTOM CLASS*********************************
private void btnAdd_Click(object sender, EventArgs e)
{
//---create an instance of the NumberMachine Class I created
NumberMachine myMathMaker = new NumberMachine();
short firstNumber = Convert.ToInt16(txtFirst.Text);
short secondNumber = Convert.ToInt16(txtSecond.Text);
myAnswer = myMathMaker.DoAddition(firstNumber, secondNumber);
lblClassAnswer.Text =Convert.ToString(myAnswer);
}
private void btnSubtract_Click(object sender, EventArgs e)
{
//---create an instance of the NumberMachine Class I created
NumberMachine myMathMaker = new NumberMachine();
short firstNumber = Convert.ToInt16(txtFirst.Text);
short secondNumber = Convert.ToInt16(txtSecond.Text);
myAnswer = myMathMaker.DoSubtraction(firstNumber, secondNumber);
lblClassAnswer.Text = Convert.ToString(myAnswer);
}
//**********************************END OF USING CUSTOM CLASS*********************************
namespace UsingClasses_Part1
{
public class NumberMachine
{
///
/// This function accepts two short integers and returns the sum as a short
///
///
///
/// Returns a short integer
public short DoAddition( short x, short y)
{
short myAnswer = 0;
myAnswer = Convert.ToInt16(x + y);
return myAnswer;
}
///
/// This function accepts two short integers subtracts them & returns the result as a short
///
///
///
///
public short DoSubtraction(int x, int y)
{
short myAnswer = 0;
myAnswer = Convert.ToInt16(x - y);
return myAnswer;
}