Beispiel #1
0
        static void Main(string[] args)
        {
            string    filePath = @"C:\Users\mohit\Documents\0006_Begining_CSharp_Collections\0003_Importing_from_dataSource_to_Array\data\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

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

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

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

            if (countries.ContainsKey(chosenRegion))
            {
                foreach (Country 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");
            }
        }
        static void Main(string[] args)
        {
            string    filePath = @"C:\Users\mohit\Documents\0006_Begining_CSharp_Collections\0003_Importing_from_dataSource_to_Array\data\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

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

            reader.RemoveCommaCountries(countries);
            Console.WriteLine("Enter no. of countries to display? ");
            bool inputIsInt = int.TryParse(Console.ReadLine(), out int userInput);

            if (!inputIsInt || userInput <= 0)
            {
                Console.WriteLine("You must enter a +ve integer. Exiting");
                return;
            }

            int maxToDisplay = userInput;

            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;
                    }
                }
                Country country = countries[i];
                Console.WriteLine($"{i+1}: {PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            }
        }
        static void Main(string[] args)
        {
            string    filePath = @"C:\Users\mohit\Documents\0006_Begining_CSharp_Collections\0003_Importing_from_dataSource_to_Array\data\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

            List <Country> countries     = reader.ReadAllCountries();
            Country        lilliput      = new Country("Lilliput", "LIL", "Somewhere", 2_000_000);
            int            lilliputIndex = countries.FindIndex(country => country.Population < 2_000_000);

            countries.Insert(lilliputIndex, lilliput);
            countries.RemoveAt(lilliputIndex);

            foreach (Country country in countries)
            {
                Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}");
            }
            Console.WriteLine($"{countries.Count} countries");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            string    filePath = @"C:\Users\mohit\Documents\0006_Begining_CSharp_Collections\0003_Importing_from_dataSource_to_Array\data\Pop by Largest Final.csv";
            CsvReader reader   = new CsvReader(filePath);

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

            var filteredCountries  = countries.Where(country => !country.Name.Contains(","));//.Take(20);
            var filteredCountries2 = from country in countries
                                     where !country.Name.Contains(',')
                                     select country;

            foreach (Country country in filteredCountries2)
            {
                Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}:" +
                                  $" {country.Name}");
            }

            for (int i = 12; i <= 14; i++)
            {
                Console.WriteLine(countries[i].Name);
            }
        }