Beispiel #1
0
        public static void SaveToFile(LuckyNumbers lNumbers)
        {
            XmlSerializer xml = new XmlSerializer(typeof(LuckyNumbers));

            using (Stream fStream = new FileStream("data.xml", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                xml.Serialize(fStream, lNumbers);
            }
        }
Beispiel #2
0
        public static void ReadFromFile()
        {
            XmlSerializer xml = new XmlSerializer(typeof(LuckyNumbers));

            try
            {
                using (Stream fStream = new FileStream("data.xml", FileMode.Open, FileAccess.Read, FileShare.None))
                {
                    luckyNumbers = (LuckyNumbers)xml.Deserialize(fStream);
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Brak pliku z losowaniami. Tworzę nowy.");
            }
        }