I'm a beginner in learning programming (and English, just saying)
I’ve tried done some research but still don’t get it...I don't know how to use string format.
By using LINQ languages, I must to display countries sorted by descending population numbers. The output of the program should format:
Country: China, Population: 1,403,500,365
etc.
After names of countries, numbers of population must format like this: 000,000,000 for all populations.
In my code I have format output for all populations numbers: 1403500365
Anny suggestions?
How to use this : String.Format("{0:#,0}", 1403500365) ?
Thanks in advance.
THIS PART IS PART OF Assignment:
using System.Linq; using System;
namespace Country.App { class Country { public string Name { get; set; } public int Population { get; set; }
public Country(string name, int population)
{
this.Name = name;
this.Population = population;
}
}
public class Program
{
public static void Main()
{
[Country\[\] countryCollection = {][1]
new Country("Afganistan", 34656032),
new Country("Austria", 8857960),
new Country("Brazil", 210147125),
new Country("Denmark", 5789957),
new Country("Russia", 144526636),
new Country("China", 1403500365),
new Country("Turkey", 80810525),
new Country("Serbia", 7001444),
new Country("Iraq", 37202572),
new Country("San Marino", 33344)
};
THIS PART IS WHAT I DONE:
Console.WriteLine("Countries sorted by descending population numbers:\n");
var countryInfo = from country in countryCollection
orderby country.Population descending, country.Name
select country;
foreach (Country Country in countryInfo)
{
Console.WriteLine(String.Format("Country: {0}, Population: {1}", Country.Name, Country.Population));
}
}
}
}