static void Main(string[] args) { string filePath = @"F:\Workspace\c-sharp-path\beginning-csharp-collections-ps\src\CollectionStudies\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).ToString().PadLeft(15)} : Countries on this List"); }
static void Main(string[] args) { string filePath = @"F:\Workspace\c-sharp-path\beginning-csharp-collections-ps\src\CollectionStudies\Pop by Largest Final.csv"; CsvReader reader = new CsvReader(filePath); List<Country> countries = reader.ReadAllCountries(); //foreach (Country country in countries.OrderBy(country => country.Name).Take(10)) // Method Syntax IEnumerable<Country> filteredCountries = countries.Where(country => !country.Name.Contains(',')).Take(20); // Query Syntax 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}"); } }