-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathProgram.cs
167 lines (146 loc) · 5.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using CountryData.Standard;
namespace CountryData.Sample.CountryConsoleProject
{
/// <summary>
/// Main program class for demonstrating the use of the CountryData library.
/// </summary>
public static class Program
{
/// <summary>
/// Static instance of CountryHelper used throughout the program.
/// </summary>
private static readonly CountryHelper _helper = new CountryHelper();
/// <summary>
/// Entry point of the program.
/// </summary>
public static void Main()
{
GetCountries();
GetCountryByCode("US");
GetCountryData();
GetRegionsByCountryCode("US");
GetCountryFlag("US");
GetPhoneCodeByCountryShortCode("AF");
GetCountryByPhoneCode("+233");
GetCurrencyCodesByCountryCode("US");
GetCountryByCurrencyCode("GHS");
GetCountryCode("Ghana");
}
/// <summary>
/// Retrieves a list of all countries and prints them to the console.
/// </summary>
private static void GetCountries()
{
var countries = _helper.GetCountries();
Console.WriteLine("Countries:");
foreach (var country in countries)
{
Console.WriteLine(country);
}
}
/// <summary>
/// Retrieves the data for a given country code and prints it to the console.
/// </summary>
/// <param name="countryCode">The ISO country code.</param>
private static void GetCountryByCode(string countryCode)
{
var country = _helper.GetCountryByCode(countryCode);
Console.WriteLine($"Country data for {countryCode}:");
Console.WriteLine(country.CountryName);
}
/// <summary>
/// Retrieves comprehensive data for all countries and prints it to the console.
/// </summary>
private static void GetCountryData()
{
var countryData = _helper.GetCountryData();
Console.WriteLine("Country data:");
foreach (var data in countryData)
{
Console.WriteLine(data.CountryName);
}
}
/// <summary>
/// Retrieves the regions for a given country code and prints them to the console.
/// </summary>
/// <param name="countryCode">The ISO country code.</param>
private static void GetRegionsByCountryCode(string countryCode)
{
var regions = _helper.GetRegionByCountryCode(countryCode);
Console.WriteLine($"Regions for {countryCode}:");
foreach (var region in regions)
{
Console.WriteLine(region.Name);
}
}
/// <summary>
/// Retrieves the emoji flag for a given country short code and prints it to the console.
/// </summary>
/// <param name="shortCode">The country short code.</param>
private static void GetCountryFlag(string shortCode)
{
var flag = _helper.GetCountryEmojiFlag(shortCode);
Console.WriteLine($"Flag for {shortCode}:");
Console.WriteLine(flag);
}
/// <summary>
/// Retrieves the phone code for a given country short code and prints it to the console.
/// </summary>
/// <param name="shortCode">The country short code.</param>
private static void GetPhoneCodeByCountryShortCode(string shortCode)
{
var phoneCode = _helper.GetPhoneCodeByCountryShortCode(shortCode);
Console.WriteLine($"Phone code for {shortCode}:");
Console.WriteLine(phoneCode);
}
/// <summary>
/// Retrieves the country name for a given phone code and prints it to the console.
/// </summary>
/// <param name="phoneCode">The phone code.</param>
private static void GetCountryByPhoneCode(string phoneCode)
{
var countries = _helper.GetCountryByPhoneCode(phoneCode);
Console.WriteLine($"Country for phone code {phoneCode}:");
foreach (var country in countries)
{
Console.WriteLine(country.CountryName);
}
}
/// <summary>
/// Retrieves and prints the currency codes for a given country code.
/// </summary>
/// <param name="shortCode">The short country code to look up currency codes for.</param>
private static void GetCurrencyCodesByCountryCode(string shortCode)
{
var currencyCodes = _helper.GetCurrencyCodesByCountryCode(shortCode);
Console.WriteLine($"Currency codes for {shortCode}:");
foreach (var currencyCode in currencyCodes)
{
Console.WriteLine(currencyCode.Code);
}
}
/// <summary>
/// Retrieves and prints the countries that use a given currency code.
/// </summary>
/// <param name="currencyCode">The currency code to look up countries for.</param>
private static void GetCountryByCurrencyCode(string currencyCode)
{
var countries = _helper.GetCountryByCurrencyCode(currencyCode);
Console.WriteLine($"Countries for currency code {currencyCode}:");
foreach (var country in countries)
{
Console.WriteLine(country.CountryName);
}
}
/// <summary>
/// Retrieves the country code for a given country name and prints it to the console.
/// </summary>
/// <param name="countryName">The name of the country.</param>
private static void GetCountryCode(string countryName)
{
using var manager = new CountryExtensions();
var result = manager.GetCountryCode(countryName);
Console.WriteLine($"Country code for {countryName} is {result} ");
}
}
}