Export (0) Print
Expand All

NumberFormatInfo.CurrentInfo Property

Gets a read-only NumberFormatInfo that formats values based on the current culture.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

public static NumberFormatInfo CurrentInfo { get; }

Property Value

Type: System.Globalization.NumberFormatInfo
A read-only NumberFormatInfo based on the culture of the current thread.

Retrieving a NumberFormatInfo object from the CurrentInfo property is equivalent to retrieving a NumberFormatInfo object from the CultureInfo.CurrentCulture.NumberFormat property.

The following example shows that the objects returned by the CurrentInfo and CultureInfo.CurrentCulture.NumberFormat properties are identical. It then uses reflection to display the property values of the NumberFormatInfo object returned by the CurrentInfo property on a system whose current culture is en-US.

using System;
using System.Collections;
using System.Globalization;
using System.Reflection;

public class Example : IComparer
{
   public static void Main()
   {
      NumberFormatInfo nfi1 = NumberFormatInfo.CurrentInfo;
      NumberFormatInfo nfi2 = CultureInfo.CurrentCulture.NumberFormat;
      Console.WriteLine("Objects equal: {0}", nfi1.Equals(nfi2));
      Console.WriteLine("Equal references: {0}\n", Object.ReferenceEquals(nfi1, nfi2));

      PropertyInfo[] props = nfi1.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
      Array.Sort(props, new Example());
      Console.WriteLine("Properties of NumberFormat.CurrentInfo object:");
      foreach (var prop in props) {
         if (prop.PropertyType.IsArray) {
            Array arr = prop.GetValue(nfi1) as Array;
            Console.Write(String.Format("   {0}: ", prop.Name) + "{ ");
            int ctr = 0;
            foreach (var item in arr) {
               Console.Write("{0}{1}", item, ctr == arr.Length - 1 ?" }" : ", ");
               ctr++;
            }
            Console.WriteLine();
         }
         else {
            Console.WriteLine("   {0}: {1}", prop.Name, prop.GetValue(nfi1));
        }   
      }      
   }

   public int Compare(Object x, Object y) 
   {
      if (x == null && y == null) return 0;

      PropertyInfo px = x as PropertyInfo;
      if (px == null) return -1;

      PropertyInfo py = y as PropertyInfo;
      if (py == null) return 1;

      return String.Compare(px.Name, py.Name);
   }
}
// The example displays the following output: 
//       Objects equal: True 
//       Equal references: True 
//        
//       Properties of NumberFormat.CurrentInfo object: 
//          CurrencyDecimalDigits: 2 
//          CurrencyDecimalSeparator: . 
//          CurrencyGroupSeparator: , 
//          CurrencyGroupSizes: { 3 } 
//          CurrencyNegativePattern: 0 
//          CurrencyPositivePattern: 0 
//          CurrencySymbol: $ 
//          DigitSubstitution: None 
//          IsReadOnly: True 
//          NaNSymbol: NaN 
//          NativeDigits: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } 
//          NegativeInfinitySymbol: -Infinity 
//          NegativeSign: - 
//          NumberDecimalDigits: 2 
//          NumberDecimalSeparator: . 
//          NumberGroupSeparator: , 
//          NumberGroupSizes: { 3 } 
//          NumberNegativePattern: 1 
//          PercentDecimalDigits: 2 
//          PercentDecimalSeparator: . 
//          PercentGroupSeparator: , 
//          PercentGroupSizes: { 3 } 
//          PercentNegativePattern: 0 
//          PercentPositivePattern: 0 
//          PercentSymbol: % 
//          PerMilleSymbol: % 
//          PositiveInfinitySymbol: Infinity 
//          PositiveSign: +

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft