@page "/"
<select @bind="_selectedCountryCode" id="select-country">
<option disabled>Select country code</option>
@foreach(var country in Countries)
{
<option value="@country.CountryCode">@country.FlagEmoji</option>
}
</select>
<p>Selected country code: @_selectedCountryCode</p>
@code {
private string _selectedCountryCode;
private HashSet<string> CountryCodes = new HashSet<string> { "DE", "US", "AC" };
private List<Country> Countries => CountryCodes
.Select(x => new Country
{
CountryCode = x,
FlagEmoji = IsoCountryCodeToFlagEmoji(x)
})
.ToList();
private string IsoCountryCodeToFlagEmoji(string countryCode) =>
string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
public class Country
{
public string CountryCode { get; set; }
public string FlagEmoji { get; set; }
}
}