Search code examples
c#sqlcultureinforegioninfo

How to get 3 digit/letter currencyCode from 3 digit ISO countryCode


I have a ddl with values that represent country codes. eg. BRA, THA, UKR, AUS etc. I need to get the preferred currency from localization settings for each of these.

I have tried checking the RegionInfo class and it is likely that the answer is somewhere in there. This link shows what i want https://www.iban.com/currency-codes

Is there any way to get the 3 digit currencyCode without using a table structure? i.e. from the pc or browser itself. Basically, if the user chooses their country as USA, then the currency should be fixed to USD. I can do this very easily with some sql. But i would like to do this without hitting the db. i.e. via RegionInfo or CultureInfo.

I cannot use new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID).ISOCurrencySymbol as it pulls from the server.


Solution

  • There is a solution about it if that 3 letter is ISO standard you can apply this code

    var c = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
          .Select(t=> new RegionInfo(t.LCID))
          .Where(t=>t.ThreeLetterISORegionName  == "USA")
          .FirstOrDefault();