public CurrencyRate(CurrencyCode code, double rate) { if (rate < 0) { throw new ArgumentException("rate can't be less than zero!", nameof(rate)); } Code = code; Rate = rate; }
public double Exchange(double sourceAmount, CurrencyCode sourceCurrencyCode, CurrencyCode destCurrencyCode) { CurrencyRate sr = this[sourceCurrencyCode]; CurrencyRate dr = this[destCurrencyCode]; double relativeRate = dr.Rate / sr.Rate; return(sourceAmount * relativeRate); }
public CurrencyRate this[CurrencyCode code] { get { if (!_data.TryGetValue(code, out var result)) { throw new ArgumentException("Unknown Currency:" + code, nameof(code)); } return(result); } }
public CurrencyTimeSeries(CurrencyCode currencyCode, IEnumerable<double> data) { CurrencyCode = currencyCode; _data = data.ToArray(); }
public CurrencyTimeSeries this[CurrencyCode code] => _data[code];