step 1
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
step2
create class ConvertCurrency
public static decimal ConvertCurrency(decimal amount, string from, string to)
{
try
{
WebClient web = new WebClient();
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = String.Format(urlPattern, from, to);
string response = new WebClient().DownloadString(url);
decimal exchangeRate = decimal.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
return exchangeRate;
}
catch (Exception ex)
{
return 0;
}
}
step 3
core function
decimal apiRate = 0;
apiRate =Class1.ConvertCurrency(1, "USD", "THB");
ไม่มีความคิดเห็น:
แสดงความคิดเห็น