Beispiel #1
0
        /// <summary>
        /// Saving to a text file what is in a character list
        /// </summary>
        private void SavePokemon()
        {
            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(FILENAME);

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

            try
            {
                sr = new StreamReader(FILENAME);
                string row = "";
                while ((row = sr.ReadLine()) != null)
                {
                    Pokemon p = PokemonMapper.ToPokemon(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();
                }
            }
        }