A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

29 lines
797 B

using System.IO;
namespace Calc.Models;
public class Calculation
{
private readonly double _firstValue;
private readonly double _secondValue;
private readonly Operator? _operator;
public Calculation(double firstValue, double secondValue, Operator? @operator)
{
_firstValue = firstValue;
_secondValue = secondValue;
_operator = @operator;
}
public double Calculate()
{
return _operator switch
{
Operator.Add => _firstValue + _secondValue,
Operator.Subtract => _firstValue - _secondValue,
Operator.Multiply => _firstValue * _secondValue,
Operator.Divide => _firstValue / _secondValue,
_ => throw new InvalidDataException("Operator not allowed")
};
}
}