public virtual HashSet <Banknote> CacheOut(int value, CurrencyType currencyType, HashSet <Banknote> banknotes) { switch (_nextHandler) { case null when value != 0: return(null); case null when value == 0: return(banknotes); default: return(_nextHandler?.CacheOut(value, currencyType, banknotes)); } }
public void CacheOut(int value, CurrencyType currencyType) { var banknotes = _handler.CacheOut(value, currencyType, new HashSet <Banknote>()); if (banknotes == null) { Console.WriteLine("Not valid input"); } else { Console.WriteLine("Success!"); foreach (var banknote in banknotes.ToList().OrderByDescending(x => x.Value)) { Console.WriteLine($"{banknote.Value} {banknote.Currency}"); } } }