Convert Country Name To Flag Emoji in C# & the .NET ecosystem
Use the same solution for CSharp Console, .NET Core, Blazor, MAUI or Xamarin iOS & Android apps
Let’s improve the User Experience of our apps today by showing flag emojis instead of the plain old country names or country codes. Using emojis over country image files significantly improves performance and dev efficiency. It is surprisingly easy and safe to implement in your applications.
Using System.Globalization
and System.Linq
, below is an example of what it looks like in a console application:

While following a javascript tips forum, I found this neat trick. But I couldn’t find a good solution in C#/.NET. But 30 days after I was about to give up, I found a solution that works great and thought it’s worthy of sharing! If you aren’t looking to run it using static functions, you can simply call GetFlag()
and pass in the country name into the function:
public string GetFlag(string country)
{
var regions = CultureInfo.GetCultures (CultureTypes. SpecificCultures).Select(x => new RegionInfo(x.LCID));
var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country));
if (englishRegion == null) return "🏳";
var countryAbbrev = englishRegion.TwoLetterISORegionName;
return IsoCountryCodeToFlagEmoji(countryAbbrev);
}public string IsoCountryCodeToFlagEmoji(string countryCode) => string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
If you already have the two digit country code, you can skip GetFlag()
simply call the IsoCountryCodeToFlagEmoji()
function.
Hope you found it useful!
Bonus XAML Converter code:
For anyone that loves converters (like Charlin & Ammar), you can just use this code to convert the Country name coming from a ViewModel property into an emoji:
public class CountryToFlagConverter : Xamarin.Forms.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => GetFlag((string)value);
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => value;
private string GetFlag(string country)
{
var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country));
if (englishRegion == null) return "🏳";
var countryAbbrev = englishRegion.TwoLetterISORegionName;
return IsoCountryCodeToFlagEmoji(countryAbbrev);
}
private string IsoCountryCodeToFlagEmoji(string countryCode)
=> string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}

After creating the converter, you can add it’s key to the ResourceDictionary of any Page like this:<local:CountryToFlagConverter x:Key=”FlagDetermination”/>
And here’s how you’d use it in your XAML:
<Label Text="{Binding GroupCountryName}"
TextColor="#424242"
HorizontalOptions="Start"
FontFamily="OpenSansBoldFont"
FontSize="22" />
<Label Text="{Binding GroupCountryName ,Converter={StaticResource FlagDetermination}}"
HorizontalOptions="EndAndExpand"
FontSize="30" />
Feel free to reach out to me with questions on Twitter or Linkedin, and check out our portfolio! Also, try our beta iOS BeAware app for the deaf, or our YouTube video on Getting Started with Xamarin Native!