Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string filePath = @"D:\PluralSight\C# Track\Beginning C# Collections\Ex Material\Pop by Largest Final.csv";

            CsvReader reader = new CsvReader(filePath);

            List <Country> belad = reader.ReadAllCountries();

            // different linq syntax

            /*
             * -Calling LINQ methods explicitly
             * var filteredCountries1 = belad.Where(x => !x.Name.Contains(','));
             *
             * -Using LINQ Syntax
             * var filteredCountries2 = from balad in belad
             *                       where !balad.Name.Contains(',')
             *                       select balad;
             */

            foreach (Country country in belad.OrderBy(x => x.Name))
            {
                Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}:{country.Name}");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string    filePath = "Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

            Dictionary <string, List <Country> > countries = reader.ReadAllCountries();

            foreach (var region in countries.Keys)
            {
                Console.WriteLine(region);
            }

            Console.WriteLine("Which of the above countries do you want? ");
            string chosenRegion = Console.ReadLine();

            if (countries.ContainsKey(chosenRegion))
            {
                foreach (var country in countries[chosenRegion].Take(10))
                {
                    Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
                }
            }
            else
            {
                Console.WriteLine("this is not a valid region");
            }

            // Console.Write("Enter the no. of countries to display> ");
            // bool inputIsInt = int.TryParse(Console.ReadLine(), out int userInput);
            // if (!inputIsInt || userInput <= 0)
            // {
            //     Console.WriteLine("You must type a positive number. Exiting...");
            //     return;
            // }

            //int maxToDisplay = userInput;


            // foreach (var country in countries.Where(x=>!x.Name.Contains(',')).Take(20))
            // {
            //     Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            // }

            // for (int i = 0; i < countries.Count; i++)
            // {
            //     if (i > 0 && (i % maxToDisplay == 0))
            //     {
            //         Console.WriteLine("Hit return to continue, anything else to quit");
            //         if(Console.ReadLine() != "")
            //             break;
            //     }
            //     var country = countries[i];
            //     Console.WriteLine($"{i+1}: {PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            //
            // }
        }
        static void Main(string[] args)
        {
            string    filePath = @"C:\CODE\pluralsight\csharp\CollectionsCourse\TopTenPops\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

            Country[] countries = reader.ReadFirstNCounrtries(10);

            foreach (Country country in countries)
            {
                Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            }
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            string    filePath = @"C:\Users\e.alencar.santos\Desktop\training [dotNET (Csharp)]\Beginning Csharp Collections\csharp-collections-beginning\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

            Dictionary <string, Country> countries = reader.ReadAllCountries();

            Console.WriteLine("Which country code do you want to look up? ");
            string userInput = Console.ReadLine();

            bool gotCountry = countries.TryGetValue(userInput, out Country country);

            if (!gotCountry)
            {
                Console.WriteLine($"Sorry, there is no country with code, {userInput} ");
            }
            else
            {
                Console.WriteLine($"{country.Name} has population {PopulationFormatter.FormatPopulation(country.Population)}");
            }

            //Country norway = new Country("Norway", "NOR", "Europe", 5282223);
            //Country finland = new Country("Finland", "FIN", "Europe", 5511303);

            //var countries = new Dictionary<string, Country>
            //{
            //    { norway.Code, norway },
            //    { finland.Code, finland }
            //};
            ////countries.Add(norway.Code, norway);
            ////countries.Add(finland.Code, finland);

            ////Console.WriteLine(countries["MUS"].Name);
            //bool exists = countries.TryGetValue("MUS", out Country country);
            //if (exists)
            //    Console.WriteLine(country.Name);
            //else
            //    Console.WriteLine($"There is no code with the code MUS");

            ////foreach (var country in countries.Values)
            ////    Console.WriteLine(country.Name);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string    filePath  = "Pop by Largest Final.csv";
            CsvReader reader    = new CsvReader(filePath);
            var       countries = reader.ReadAllCountries();

            Console.WriteLine("Which country code do you want to look up");
            var userInput = Console.ReadLine();

            bool gotCountry = countries.TryGetValue(userInput, out Country country);

            if (!gotCountry)
            {
                Console.WriteLine($"Sorry, there is no country with the code, {userInput}");
            }
            else
            {
                Console.WriteLine($"{country.Name} has a population {PopulationFormatter.FormatPopulation(country.Population)}");
            }
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            //    string[] strings = new string[5];
            //    char[] chars = new char[5];
            //    int[] ints = new int[5];
            //    string string2;
            //    char char2;
            //    int int2;
            //    int teressa;

            string    filePath = @"C:\...\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

            Country[] countries = reader.ReadFirstNCountries(10);

            foreach (Country country in countries)
            {
                Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            //Change this variable to the path of your file
            string filePath = @"C:\Users\CNova\Documents\Estagio\Curso Pluralsight C#\csharp-collections-beginning\Pop by Largest Final.csv";

            CsvReader reader = new CsvReader(filePath);
            Dictionary <string, Country> countries = reader.ReadAllCountries();

            Console.WriteLine("Wich country code do you want to look up? ");
            string userInput = Console.ReadLine();

            bool gotCountry = countries.TryGetValue(userInput, out Country country);

            if (!gotCountry)
            {
                Console.WriteLine($"Sorry, there is no country with code, {userInput}");
            }

            else
            {
                Console.WriteLine($"{country.Name} has population {PopulationFormatter.FormatPopulation(country.Population)}");
            }
        }