static void Main(string[] args) { //// Declaring, not instantiating //Country[] countries = null; //// Specifying only the size //Country[] countries = new Country[nCountries]; //// Specifying the values Country[] countries = new Country[] { new Country("United Kingdom", "GBR", "Europe", 66_000_000), new Country("Nepal", "NPL", "Asia", 29_000_000) }; // OK. int[] is a reference type int[] numbers = null; // Wrong. int is a value type so can't be null int number = null; string filePath = @"G:\G_Work\Pluralsight\Courses\Beginning Effective Collections\Code\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}"); } } }
static void Main(string[] args) { string filePath = @"G:\G_Work\Pluralsight\Courses\Beginning Effective Collections\Code\Pop by Largest Final.csv"; CsvReader reader = new CsvReader(filePath); // using the array with an interface IList <Country> countries = reader.ReadFirstNCountries(10); foreach (Country country in countries) { Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population).PadLeft(15)}: {country.Name}"); } }
static void Main(string[] args) { string filePath = @"C:\Users\Rui Reis\program\learning\dotnet\pluralsight\Robinson_Beginning_CSharp_Collections\code\Pop by Largest Final.csv"; CsvReader reader = new CsvReader(filePath); Dictionary <string, Country> countries = reader.ReadAllCountries(); WriteLine("Which country code do you want to look up?"); string user_input = ReadLine(); bool gotCountry = countries.TryGetValue(user_input, out Country country); if (!gotCountry) { WriteLine($"Sorry, there is no country with the code, {user_input}."); } else { WriteLine($"{country.Name} has population {PopulationFormatter.FormatPopulation(country.Population)}."); } // Country[] countries = reader.ReadFirstNCountries(10); //List<Country> countries = reader.ReadAllCountries(); //Country lilliput = new Country("Lilliput", "LIL", "Somewhere", 2_000_000); //int lilliputIndex = countries.FindIndex(x => x.Population < 2_000_000); //countries.Insert(lilliputIndex, lilliput); //countries.RemoveAt(lilliputIndex); //foreach (Country country in countries) //{ // Console.WriteLine($"{PopulationFormatter.FormatPopulation(country.Population),-15}: { country.Name}"); //} //Console.WriteLine($"{countries.Count} countries."); }