CKTIS / C#
Get a region’s currency code with RegionInfo.ISOCurrencySymbol
Read the ISO 4217 currency code for an explicit region and distinguish it from the region code and the symbol displayed next to an amount.
Version: C# 12 and .NET 8; later runtimes may add compatible features
Syntax
public virtual string ISOCurrencySymbol { get; }
// Usage inside a method or in top-level code:
string currencyCode = new System.Globalization.RegionInfo("en-US").ISOCurrencySymbol;System.Globalization.RegionInfo/ISOCurrencySymbol denotes the ISOCurrencySymbol property on the RegionInfo class in the System.Globalization namespace. It is a public, virtual instance property with no setter. Read it without parentheses to get a string containing the region’s three-character ISO 4217 currency code, such as USD.
The RegionInfo(string) constructor accepts a region code such as US or a specific culture name such as en-US. Using en-US selects the region explicitly rather than relying on current regional settings. The neutral name en does not identify a region and throws ArgumentException; passing null throws ArgumentNullException. Globalization-invariant mode can prevent construction. The separate RegionInfo(int) overload takes a culture identifier, not a numeric currency code.
For en-US, TwoLetterISORegionName returns US (region code), ISOCurrencySymbol returns USD (currency code), and CurrencySymbol returns $ with standard settings. A symbol like $ can represent more than one currency. Store a transaction’s actual currency code with its amount; regional data does not determine the currency of a transaction or convert amounts.
Formatting is a separate task. CultureInfo implements System.IFormatProvider, and its GetFormat(Type) method supplies objects such as NumberFormatInfo for numeric formatting. amount.ToString("C", culture) uses the supplied culture’s currency-formatting rules; it neither reads ISOCurrencySymbol nor converts the amount.
Examples
using System;
using System.Globalization;
var region = new RegionInfo("en-US");
Console.WriteLine($"Region: {region.TwoLetterISORegionName}");
Console.WriteLine($"Currency code: {region.ISOCurrencySymbol}");
Console.WriteLine($"Display symbol: {region.CurrencySymbol}");Result
Region: US Currency code: USD Display symbol: $
The program reads three properties for the explicitly selected `en-US` culture. The expected output assumes standard `en-US` globalization data and settings with globalization-invariant mode disabled.
Related lessons
- C# · Lesson 34 · Advanced · Version: 3
Sources
- RegionInfo.ISOCurrencySymbol Property (System.Globalization)
- RegionInfo Constructor (System.Globalization)
- RegionInfo.CurrencySymbol Property (System.Globalization)
- RegionInfo.TwoLetterISORegionName Property (System.Globalization)
- IFormatProvider Interface (System)
- Standard numeric format strings
- Runtime configuration options for globalization