Also the URL uses ISO 4217 for denoting currencies. Why do I mention this? Because if we pass in data that conforms to what the URL expects, we can reduce the code from:
Also the URL uses ISO 4217. Why do I mention this? Because if we pass in data that conforms to what the URL expects, we can reduce the code from:
Also the URL uses ISO 4217 for denoting currencies. Why do I mention this? Because if we pass in data that conforms to what the URL expects, we can reduce the code from:
I notice that you're using terms like "dollar" and "euro" to denote currency. This is fine, but there are questions like which dollar. Looking at the code, it uses USD, but dollar can also mean AUD for example.
Also the URL uses ISO 4217. Why do I mention this? Because if we pass in data that conforms to what the URL expects, we can reduce the code from:
static double PerformConversion(string firstCurrency, string secondCurrency, double currencyValue) { var client = new WebClient(); var usdToEur = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/usd/eur"); var usdToRon = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/usd/ron"); var eurToUsd = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/eur/usd"); var eurToRon = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/eur/ron"); var ronToUsd = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/ron/usd"); var ronToEur = client.DownloadString("http://currencies.apps.grandtrunk.net/getlatest/ron/eur"); if (firstCurrency == "dollar" && secondCurrency == "euro") { return currencyValue * Convert.ToDouble(usdToEur); } if (firstCurrency == "dollar" && secondCurrency == "ron") { return currencyValue * Convert.ToDouble(usdToRon); } if (firstCurrency == "euro" && secondCurrency == "dollar") { return currencyValue * Convert.ToDouble(eurToUsd); } if (firstCurrency == "euro" && secondCurrency == "ron") { return currencyValue * Convert.ToDouble(eurToRon); } if (firstCurrency == "ron" && secondCurrency == "dollar") { return currencyValue * Convert.ToDouble(ronToUsd); } if (firstCurrency == "ron" && secondCurrency == "euro") { return currencyValue * Convert.ToDouble(ronToEur); } return currencyValue; } To
static double PerformConversion(string firstCurrency, string secondCurrency, double currencyValue) { var client = new WebClient(); var conversionRateResponse = client.DownloadString($"http://currencies.apps.grandtrunk.net/getlatest/{firstCurrency}/{secondCurrency}"); return currencyValue * Convert.ToDouble(conversionRateResponse); } Also, WebClient is deprecated (prefer to use HttpClient instead), however it should be fine for your use case.