Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Xml.Serialization;
- namespace Kurs
- {
- [XmlRoot("tabela_kursow")]
- public class XmlData
- {
- [XmlElement("pozycja")]
- public List<pozycja> Currencies { get; set; }
- }
- public class pozycja
- {
- public string nazwa_waluty { get; set; }
- public string przelicznik { get; set; }
- public string kod_waluty { get; set; }
- public string kurs_sredni { get; set; }
- public double GetValue()
- {
- return double.Parse(kurs_sredni.Replace(',', '.'));
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- String URLString = "http://www.nbp.pl/Kursy/XML/LastA.xml";
- XmlTextReader reader = new XmlTextReader(URLString);
- var ser = new XmlSerializer(typeof(XmlData));
- XmlData data = (XmlData)ser.Deserialize(reader);
- double price = data.Currencies.Find(i => i.kod_waluty.Equals("USD")).GetValue();
- System.Console.WriteLine(price.ToString());
- System.Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment