Ejemplo n.º 1
0
        /**
         *      RetrieveVolcanoData
         *          static utility method to read the volcano.csv file and
         *          convert to a List<Volcano> object
         *
         */
        public static List <Volcano> LoadVolcanoData()
        {
            var            volcanoes  = Utils.ReadFile("volcano.csv");
            List <Volcano> lVolcanoes = new List <Volcano>();

            foreach (var vText in volcanoes)
            {
                string[] attrib = vText.Split(",");
                //  Country,Death,Elevation,Location,Name,Type,VEI,Year
                Volcano v = new Volcano(
                    attrib[0], Utils.StrToInt(attrib[1]), Utils.StrToInt(attrib[2]),
                    attrib[3], attrib[4], attrib[5], Utils.StrToInt(attrib[6]),
                    Utils.StrToInt(attrib[7]));
                lVolcanoes.Add(v);
            }
            lVolcanoes.Remove(lVolcanoes[0]);       //  Remove the header row
            return(lVolcanoes);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //  read a file from your hard drive with a list of all Volcanoes
            List <Volcano> lVolcanoes = Volcano.LoadVolcanoData();

            //  Using the LINQ method Where get all Volcanoes since 2015
            var v2015 = lVolcanoes.Where(v => v.Year > 2015);

            //  Using the LINQ method ForEach print all Volcanoes since 2015
            v2015.ToList().ForEach(v => Console.WriteLine(v));

            //  Using LINQ count the deaths since 2015
            int deaths = v2015.Sum(v => v.Deaths);

            Console.WriteLine($"Since 1995 there have been {deaths} deaths from {v2015.Count()} eruptions");

            //  get all volcanoes for the 18th century
            //  what is the average number of deaths where the number of deaths was greater than 0
            //  what was the total number of deaths
            //  what was the max elevation
            //  order the volcanoes by elevation tallest to shortest
            //  what was the 'shortest' volcanoe (Last)
            //  get a list of the the 5th to 10th tallest volcanoes (Skip and Take)
        }