Exemple #1
0
 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);
     }
 }
Exemple #4
0
 public CurrencyTimeSeries(CurrencyCode currencyCode, IEnumerable<double> data)
 {
     CurrencyCode = currencyCode;
     _data = data.ToArray();
 }
Exemple #5
0
 public CurrencyTimeSeries this[CurrencyCode code] => _data[code];