public ActionResult Index()
{
XmlTextReader oku = new XmlTextReader("http://www.tcmb.gov.tr/kurlar/today.xml");
XmlDocument dok = new XmlDocument();
dok.Load(oku);
XmlNode xdollar = dok.SelectSingleNode("/Tarih_Date/Currency[CurrencyName='US DOLLAR']");
XmlNode xeuro = dok.SelectSingleNode("/Tarih_Date/Currency[CurrencyName='EURO']");
XmlNode xsterling = dok.SelectSingleNode("/Tarih_Date/Currency[CurrencyName='POUND STERLING']");
double dolar = double.Parse(xdollar.ChildNodes[4].InnerText);
double euro = double.Parse(xeuro.ChildNodes[4].InnerText);
double sterling = double.Parse(xsterling.ChildNodes[4].InnerText);
ViewData["dolar"] = dolar;
ViewData["euro"] = euro;
ViewData["sterling"] = sterling;
//ya da
Func<XmlNode, double> fnc = delegate(XmlNode x) {
return double.Parse(x.ChildNodes[4].InnerText);
};
ViewData["dolar"] = fnc(xdollar);
ViewData["euro"] = fnc(xeuro);
ViewData["sterling"] = fnc(xsterling);
//ya da
Func<XmlNode, double> fnc = delegate(XmlNode x) {
return double.Parse(x.ChildNodes[4].InnerText);
};
ViewData["dolar"] = fnc(xdollar);
ViewData["euro"] = fnc(xeuro);
ViewData["sterling"] = fnc(xsterling);
return View();
}
//*************************************//
<h2>Index</h2>
Dolar: @ViewData["dolar"]<hr />
Euro: @ViewData["euro"]<hr />
Sterling: @ViewData["sterling"]
çok teşekkür ederim çok yardımcı oldu bu yazı :)
YanıtlaSil