Guest User

Untitled

a guest
Jul 23rd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. using System.Xml.Serialization;
  8.  
  9. namespace Kurs
  10. {
  11.  
  12.     [XmlRoot("tabela_kursow")]
  13.     public class XmlData
  14.     {
  15.         [XmlElement("pozycja")]
  16.         public List<pozycja> Currencies { get; set; }
  17.     }
  18.  
  19.     public class pozycja
  20.     {
  21.         public string nazwa_waluty { get; set; }
  22.         public string przelicznik { get; set; }
  23.         public string kod_waluty { get; set; }
  24.         public string kurs_sredni { get; set; }
  25.         public double GetValue()
  26.         {
  27.             return double.Parse(kurs_sredni.Replace(',', '.'));
  28.         }
  29.     }
  30.  
  31.     class Program
  32.     {
  33.         static void Main(string[] args)
  34.         {
  35.             String URLString = "http://www.nbp.pl/Kursy/XML/LastA.xml";
  36.             XmlTextReader reader = new XmlTextReader(URLString);
  37.             var ser = new XmlSerializer(typeof(XmlData));
  38.             XmlData data = (XmlData)ser.Deserialize(reader);
  39.             double price = data.Currencies.Find(i => i.kod_waluty.Equals("USD")).GetValue();
  40.             System.Console.WriteLine(price.ToString());
  41.             System.Console.ReadKey();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment