Пример #1
0
        /// <summary>
        /// Saving to a text file what is in a character list
        /// </summary>
        private void SaveMoves()
        {
            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(FILENAME);

                foreach (Moves pokemon in pokemon)
                {
                    sw.WriteLine(MovesMapper.toStringCSV(pokemon));
                    sw.Flush();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong");
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Load from a text file into the pokemon list
        /// </summary>
        private void LoadMoves()
        {
            List <Moves> results = new List <Moves>();
            StreamReader sr      = null;

            try
            {
                sr = new StreamReader(FILENAME);
                string row = "";
                while ((row = sr.ReadLine()) != null)
                {
                    Moves p = MovesMapper.ToMoves(row);
                    results.Add(p);
                }
                pokemon = results;
            }
            catch (FileNotFoundException fileNotFound)
            {
                Console.WriteLine(fileNotFound.FileName + " was not found");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }