From 77bb946fcb8c16c8dad9acee4d8f3b71a175d1c2 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 3 Jun 2026 21:05:25 -0700 Subject: [PATCH 1/8] Reinstate supplemental remarks --- .../CultureInfo/CurrentCulture/Async1.cs | 39 ++ .../CultureInfo/CurrentCulture/Get1.cs | 15 + .../CultureInfo/CurrentCulture/Project.csproj | 8 + .../CurrentCulture/aspculture13.cs | 20 + .../CurrentCulture/changeculture11.cs | 33 ++ .../CultureInfo/CurrentCulture/specific12.cs | 26 ++ .../CultureInfo/CurrentUICulture/Async1.cs | 39 ++ .../CultureInfo/CurrentUICulture/Get1.cs | 15 + .../CurrentUICulture/Project.csproj | 8 + .../CurrentUICulture/currentuiculture1.cs | 18 + .../CultureInfo/InvariantCulture/persist1.cs | 50 +++ .../DateTimeFormatInfo/create1.cs | 112 +++++ .../DateTimeFormatInfo/create2.cs | 25 ++ .../DateTimeFormatInfo/example1.cs | 28 ++ .../DateTimeFormatInfo/example2.cs | 39 ++ .../DateTimeFormatInfo/example3.cs | 23 + .../DateTimeFormatInfo/example4.cs | 47 +++ .../DateTimeFormatInfo/example5.cs | 47 +++ .../DateTimeFormatInfo/formatprovider1.cs | 42 ++ .../DateTimeFormatInfo/instantiate2.cs | 21 + .../DateTimeFormatInfo/instantiate3.cs | 32 ++ .../DateTimeFormatInfo/instantiate6.cs | 119 ++++++ .../DateTimeFormatInfo/parse1.cs | 45 ++ .../DateTimeFormatInfo/parse2.cs | 36 ++ .../DateTimeFormatInfo/project.csproj | 9 + .../DateTimeFormatInfo/serialize1.cs | 28 ++ .../DateTimeFormatInfo/serialize2.cs | 29 ++ .../CultureInfo/CurrentCulture/Async1.vb | 42 ++ .../CultureInfo/CurrentCulture/Get1.vb | 16 + .../CultureInfo/CurrentCulture/Program.vb | 5 + .../CultureInfo/CurrentCulture/Project.vbproj | 8 + .../CurrentCulture/aspculture13.vb | 23 + .../CurrentCulture/changeculture11.vb | 35 ++ .../CultureInfo/CurrentCulture/specific12.vb | 30 ++ .../CultureInfo/CurrentUICulture/Async1.vb | 42 ++ .../CultureInfo/CurrentUICulture/Get1.vb | 16 + .../CurrentUICulture/Project.vbproj | 8 + .../CurrentUICulture/currentuiculture1.vb | 20 + .../InvariantCulture/Project.vbproj | 8 + .../CultureInfo/InvariantCulture/persist1.vb | 53 +++ xml/System.Globalization/CompareInfo.xml | 26 +- xml/System.Globalization/CompareOptions.xml | 12 +- xml/System.Globalization/CultureInfo.xml | 396 +++++++++++++++++- .../DateTimeFormatInfo.xml | 359 +++++++++++++++- xml/System.Globalization/NumberFormatInfo.xml | 226 +++++++++- xml/System.Globalization/PersianCalendar.xml | 33 +- xml/System.Globalization/RegionInfo.xml | 30 +- xml/System.Globalization/SortKey.xml | 43 +- xml/System.Globalization/SortVersion.xml | 43 +- xml/System.IO/FileStream.xml | 34 +- xml/System.IO/FileSystemWatcher.xml | 49 ++- 51 files changed, 2491 insertions(+), 19 deletions(-) create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Get1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Project.csproj create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/InvariantCulture/persist1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs create mode 100644 snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Get1.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Program.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Project.vbproj create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Project.vbproj create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/Project.vbproj create mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/persist1.vb diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs new file mode 100644 index 00000000000..862b15bbfd7 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs @@ -0,0 +1,39 @@ +// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Runtime.Versioning; +using System.Threading; +using System.Threading.Tasks; + +public class Example14 +{ + public static async Task Main() + { + var tasks = new List(); + Console.WriteLine($"The current culture is {Thread.CurrentThread.CurrentCulture.Name}"); + Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR"); + // Change the current culture to Portuguese (Brazil). + Console.WriteLine($"Current culture changed to {Thread.CurrentThread.CurrentCulture.Name}"); + Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}"); + // Launch six tasks and display their current culture. + for (int ctr = 0; ctr <= 5; ctr++) + tasks.Add(Task.Run(() => + { + Console.WriteLine($"Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentCulture.Name}"); + })); + + await Task.WhenAll(tasks.ToArray()); + } +} +// The example displays output like the following: +// The current culture is en-US +// Current culture changed to pt-BR +// Application thread is thread 9 +// Culture of task 2 on thread 11 is pt-BR +// Culture of task 1 on thread 10 is pt-BR +// Culture of task 3 on thread 11 is pt-BR +// Culture of task 5 on thread 11 is pt-BR +// Culture of task 6 on thread 11 is pt-BR +// Culture of task 4 on thread 10 is pt-BR +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs new file mode 100644 index 00000000000..f07ebd7151e --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs @@ -0,0 +1,15 @@ +// +using System; +using System.Globalization; + +public class Example5 +{ + public static void Main() + { + CultureInfo culture = CultureInfo.CurrentCulture; + Console.WriteLine($"The current culture is {culture.NativeName} [{culture.Name}]"); + } +} +// The example displays output like the following: +// The current culture is English (United States) [en-US] +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj new file mode 100644 index 00000000000..874c98f3477 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj @@ -0,0 +1,8 @@ + + + + Library + net10.0 + + + diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs new file mode 100644 index 00000000000..f35caeb4dc8 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Threading; + +public class Example13 +{ + public static void Main() + { + // + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(Request13.UserLanguages[0]); + // + } +} + +public class Request13 +{ + private static string[] langs = new string[3]; + + public static string[] UserLanguages { get { return langs; } } +} diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs new file mode 100644 index 00000000000..699931f4242 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs @@ -0,0 +1,33 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class Info11 : MarshalByRefObject +{ + public void ShowCurrentCulture() + { + Console.WriteLine($"Culture of {Thread.CurrentThread.Name} in application domain {AppDomain.CurrentDomain.FriendlyName}: {CultureInfo.CurrentCulture.Name}"); + } +} + +public class Example11 +{ + public static void Main() + { + Info11 inf = new Info11(); + // Set the current culture to Dutch (Netherlands). + Thread.CurrentThread.Name = "MainThread"; + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL"); + inf.ShowCurrentCulture(); + + // Create a new application domain. + AppDomain ad = AppDomain.CreateDomain("Domain2"); + Info11 inf2 = (Info11)ad.CreateInstanceAndUnwrap(typeof(Info11).Assembly.FullName, "Info11"); + inf2.ShowCurrentCulture(); + } +} +// The example displays the following output: +// Culture of MainThread in application domain ChangeCulture1.exe: nl-NL +// Culture of MainThread in application domain Domain2: nl-NL +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs new file mode 100644 index 00000000000..85f7b6e54eb --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs @@ -0,0 +1,26 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class Example12 +{ + public static void Main() + { + double value = 1634.92; + CultureInfo.CurrentCulture = new CultureInfo("fr-CA"); + Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}"); + Console.WriteLine($"{value:C2}\n"); + + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr"); + Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}"); + Console.WriteLine($"{value:C2}"); + } +} +// The example displays the following output: +// Current Culture: fr-CA +// 1 634,92 $ +// +// Current Culture: fr +// 1 634,92 € +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs new file mode 100644 index 00000000000..37fc0573971 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs @@ -0,0 +1,39 @@ +// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Runtime.Versioning; +using System.Threading; +using System.Threading.Tasks; + +public class Example +{ + public static async Task Main() + { + var tasks = new List(); + Console.WriteLine($"The current UI culture is {Thread.CurrentThread.CurrentUICulture.Name}"); + Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR"); + // Change the current UI culture to Portuguese (Brazil). + Console.WriteLine($"Current UI culture changed to {Thread.CurrentThread.CurrentUICulture.Name}"); + Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}"); + // Launch six tasks and display their current culture. + for (int ctr = 0; ctr <= 5; ctr++) + tasks.Add(Task.Run(() => + { + Console.WriteLine($"UI Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentUICulture.Name}"); + })); + + await Task.WhenAll(tasks.ToArray()); + } +} +// The example displays output like the following: +// The current UI culture is en-US +// Current UI culture changed to pt-BR +// Application thread is thread 9 +// UI Culture of task 2 on thread 11 is pt-BR +// UI Culture of task 1 on thread 10 is pt-BR +// UI Culture of task 3 on thread 11 is pt-BR +// UI Culture of task 5 on thread 11 is pt-BR +// UI Culture of task 6 on thread 11 is pt-BR +// UI Culture of task 4 on thread 10 is pt-BR +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Get1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Get1.cs new file mode 100644 index 00000000000..62eb67f1b7d --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Get1.cs @@ -0,0 +1,15 @@ +// +using System; +using System.Globalization; + +public class Example2 +{ + public static void Main() + { + CultureInfo culture = CultureInfo.CurrentUICulture; + Console.WriteLine($"The current UI culture is {culture.NativeName} [{culture.Name}]"); + } +} +// The example displays output like the following: +// The current UI culture is English (United States) [en-US] +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Project.csproj b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Project.csproj new file mode 100644 index 00000000000..874c98f3477 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Project.csproj @@ -0,0 +1,8 @@ + + + + Library + net10.0 + + + diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs new file mode 100644 index 00000000000..8c1432d7829 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs @@ -0,0 +1,18 @@ +// +using System; +using System.Globalization; + +public class Example1 +{ + public static void Main() + { + Console.WriteLine($"The current UI culture: {CultureInfo.CurrentUICulture.Name}"); + + CultureInfo.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); + Console.WriteLine($"The current UI culture: {CultureInfo.CurrentUICulture.Name}"); + } +} +// The example displays output like the following: +// The current UI culture: en-US +// The current UI culture: fr-FR +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/InvariantCulture/persist1.cs b/snippets/csharp/System.Globalization/CultureInfo/InvariantCulture/persist1.cs new file mode 100644 index 00000000000..9d21620ea6a --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/InvariantCulture/persist1.cs @@ -0,0 +1,50 @@ +// +using System; +using System.IO; +using System.Globalization; + +public class Example +{ + public static void Main() + { + // Persist the date and time data. + StreamWriter sw = new StreamWriter(@".\DateData.dat"); + + // Create a DateTime value. + DateTime dtIn = DateTime.Now; + // Retrieve a CultureInfo object. + CultureInfo invC = CultureInfo.InvariantCulture; + + // Convert the date to a string and write it to a file. + sw.WriteLine(dtIn.ToString("r", invC)); + sw.Close(); + + // Restore the date and time data. + StreamReader sr = new StreamReader(@".\DateData.dat"); + String input; + while ((input = sr.ReadLine()) != null) + { + Console.WriteLine($"Stored data: {input}\n"); + + // Parse the stored string. + DateTime dtOut = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind); + + // Create a French (France) CultureInfo object. + CultureInfo frFr = new CultureInfo("fr-FR"); + // Displays the date formatted for the "fr-FR" culture. + Console.WriteLine($"Date formatted for the {frFr.Name} culture: {dtOut.ToString("f", frFr)}"); + + // Creates a German (Germany) CultureInfo object. + CultureInfo deDe= new CultureInfo("de-De"); + // Displays the date formatted for the "de-DE" culture. + Console.WriteLine($"Date formatted for {deDe.Name} culture: {dtOut.ToString("f", deDe)}"); + } + sr.Close(); + } +} +// The example displays the following output: +// Stored data: Tue, 15 May 2012 16:34:16 GMT +// +// Date formatted for the fr-FR culture: mardi 15 mai 2012 16:34 +// Date formatted for de-DE culture: Dienstag, 15. Mai 2012 16:34 +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs new file mode 100644 index 00000000000..9c54c076ec0 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs @@ -0,0 +1,112 @@ +using System; + +public class Example +{ + public static void Main() + { + CreateInvariant1(); + Console.WriteLine(); + CreateNeutral2(); + Console.WriteLine(); + CreateSpecific3(); + } + + private static void CreateInvariant1() + { + // + System.Globalization.DateTimeFormatInfo dtfi; + + dtfi = System.Globalization.DateTimeFormatInfo.InvariantInfo; + Console.WriteLine(dtfi.IsReadOnly); + + dtfi = new System.Globalization.DateTimeFormatInfo(); + Console.WriteLine(dtfi.IsReadOnly); + + dtfi = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat; + Console.WriteLine(dtfi.IsReadOnly); + // The example displays the following output: + // True + // False + // True + // + } + + private static void CreateNeutral2() + { + // + System.Globalization.CultureInfo specific, neutral; + System.Globalization.DateTimeFormatInfo dtfi; + + // Instantiate a culture by creating a specific culture and using its Parent property. + specific = System.Globalization.CultureInfo.GetCultureInfo("fr-FR"); + neutral = specific.Parent; + dtfi = neutral.DateTimeFormat; + Console.WriteLine($"{neutral.Name} from Parent property: {dtfi.IsReadOnly}"); + + dtfi = System.Globalization.CultureInfo.GetCultureInfo("fr-FR").Parent.DateTimeFormat; + Console.WriteLine($"{neutral.Name} from Parent property: {dtfi.IsReadOnly}"); + + // Instantiate a neutral culture using the CultureInfo constructor. + neutral = new System.Globalization.CultureInfo("fr"); + dtfi = neutral.DateTimeFormat; + Console.WriteLine($"{neutral.Name} from CultureInfo constructor: {dtfi.IsReadOnly}"); + + // Instantiate a culture using CreateSpecificCulture. + neutral = System.Globalization.CultureInfo.CreateSpecificCulture("fr"); + dtfi = neutral.DateTimeFormat; + Console.WriteLine($"{neutral.Name} from CreateSpecificCulture: {dtfi.IsReadOnly}"); + + // Retrieve a culture by calling the GetCultureInfo method. + neutral = System.Globalization.CultureInfo.GetCultureInfo("fr"); + dtfi = neutral.DateTimeFormat; + Console.WriteLine($"{neutral.Name} from GetCultureInfo: {dtfi.IsReadOnly}"); + + // Instantiate a DateTimeFormatInfo object by calling GetInstance. + neutral = System.Globalization.CultureInfo.CreateSpecificCulture("fr"); + dtfi = System.Globalization.DateTimeFormatInfo.GetInstance(neutral); + Console.WriteLine($"{neutral.Name} from GetInstance: {dtfi.IsReadOnly}"); + + // The example displays the following output: + // fr from Parent property: False + // fr from Parent property: False + // fr from CultureInfo constructor: False + // fr-FR from CreateSpecificCulture: False + // fr from GetCultureInfo: True + // fr-FR from GetInstance: False + // + } + + private static void CreateSpecific3() + { + // + System.Globalization.CultureInfo ci = null; + System.Globalization.DateTimeFormatInfo dtfi = null; + + // Instantiate a culture using CreateSpecificCulture. + ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); + dtfi = ci.DateTimeFormat; + Console.WriteLine($"{ci.Name} from CreateSpecificCulture: {dtfi.IsReadOnly}"); + + // Instantiate a culture using the CultureInfo constructor. + ci = new System.Globalization.CultureInfo("en-CA"); + dtfi = ci.DateTimeFormat; + Console.WriteLine($"{ci.Name} from CultureInfo constructor: {dtfi.IsReadOnly}"); + + // Retrieve a culture by calling the GetCultureInfo method. + ci = System.Globalization.CultureInfo.GetCultureInfo("en-AU"); + dtfi = ci.DateTimeFormat; + Console.WriteLine($"{ci.Name} from GetCultureInfo: {dtfi.IsReadOnly}"); + + // Instantiate a DateTimeFormatInfo object by calling DateTimeFormatInfo.GetInstance. + ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"); + dtfi = System.Globalization.DateTimeFormatInfo.GetInstance(ci); + Console.WriteLine($"{ci.Name} from GetInstance: {dtfi.IsReadOnly}"); + + // The example displays the following output: + // en-US from CreateSpecificCulture: False + // en-CA from CultureInfo constructor: False + // en-AU from GetCultureInfo: True + // en-GB from GetInstance: False + // + } +} diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs new file mode 100644 index 00000000000..01e02d14e15 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; + +public class Create2Ex +{ + public static void Main() + { + // + DateTimeFormatInfo dtfi; + + dtfi = DateTimeFormatInfo.CurrentInfo; + Console.WriteLine(dtfi.IsReadOnly); + + dtfi = CultureInfo.CurrentCulture.DateTimeFormat; + Console.WriteLine(dtfi.IsReadOnly); + + dtfi = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentCulture); + Console.WriteLine(dtfi.IsReadOnly); + // The example displays the following output: + // True + // True + // True + // + } +} diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs new file mode 100644 index 00000000000..329b9ee31e8 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs @@ -0,0 +1,28 @@ +// +using System; +using System.Globalization; + +public class Example1 +{ + public static void Main() + { + DateTime dateValue = new DateTime(2013, 8, 18); + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + DateTimeFormatInfo dtfi = enUS.DateTimeFormat; + + Console.WriteLine("Before modifying DateTimeFormatInfo object: "); + Console.WriteLine($"{dtfi.ShortDatePattern}: {dateValue.ToString("d", enUS)}\n"); + + // Modify the short date pattern. + dtfi.ShortDatePattern = "yyyy-MM-dd"; + Console.WriteLine("After modifying DateTimeFormatInfo object: "); + Console.WriteLine($"{dtfi.ShortDatePattern}: {dateValue.ToString("d", enUS)}"); + } +} +// The example displays the following output: +// Before modifying DateTimeFormatInfo object: +// M/d/yyyy: 8/18/2013 +// +// After modifying DateTimeFormatInfo object: +// yyyy-MM-dd: 2013-08-18 +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs new file mode 100644 index 00000000000..3ff54e26a15 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs @@ -0,0 +1,39 @@ +// +using System; +using System.Globalization; + +public class Example2 +{ + public static void Main() + { + DateTime value = new DateTime(2013, 7, 9); + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + DateTimeFormatInfo dtfi = enUS.DateTimeFormat; + String[] formats = { "D", "F", "f" }; + + // Display date before modifying properties. + foreach (var fmt in formats) + Console.WriteLine($"{fmt}: {value.ToString(fmt, dtfi)}"); + + Console.WriteLine(); + + // We don't want to change the FullDateTimePattern, so we need to save it. + String originalFullDateTimePattern = dtfi.FullDateTimePattern; + + // Modify day name abbreviations and long date pattern. + dtfi.AbbreviatedDayNames = new String[] { "Su", "M", "Tu", "W", "Th", "F", "Sa" }; + dtfi.LongDatePattern = "ddd dd-MMM-yyyy"; + dtfi.FullDateTimePattern = originalFullDateTimePattern; + foreach (var fmt in formats) + Console.WriteLine($"{fmt}: {value.ToString(fmt, dtfi)}"); + } +} +// The example displays the following output: +// D: Tuesday, July 9, 2013 +// F: Tuesday, July 9, 2013 12:00:00 AM +// f: Tuesday, July 9, 2013 12:00 AM +// +// D: Tu 09-Jul-2013 +// F: Tuesday, July 9, 2013 12:00:00 AM +// f: Tu 09-Jul-2013 12:00 AM +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs new file mode 100644 index 00000000000..925227609f5 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs @@ -0,0 +1,23 @@ +// +using System; +using System.Globalization; + +public class Example3 +{ + public static void Main() + { + DateTime dateValue = new DateTime(2013, 08, 28); + CultureInfo frFR = CultureInfo.CreateSpecificCulture("fr-FR"); + DateTimeFormatInfo dtfi = frFR.DateTimeFormat; + + Console.WriteLine($"Before modifying DateSeparator property: {dateValue.ToString("g", frFR)}"); + + // Modify the date separator. + dtfi.DateSeparator = "-"; + Console.WriteLine($"After modifying the DateSeparator property: {dateValue.ToString("g", frFR)}"); + } +} +// The example displays the following output: +// Before modifying DateSeparator property: 28/08/2013 00:00 +// After modifying the DateSeparator property: 28-08-2013 00:00 +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs new file mode 100644 index 00000000000..14f4fc81404 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs @@ -0,0 +1,47 @@ +// +using System; +using System.Globalization; + +public class Example4 +{ + public static void Main() + { + DateTime dateValue = new DateTime(2013, 5, 18, 13, 30, 0); + String[] formats = { "D", "f", "F" }; + + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + DateTimeFormatInfo dtfi = enUS.DateTimeFormat; + String originalLongDatePattern = dtfi.LongDatePattern; + + // Display the default form of three long date formats. + foreach (var fmt in formats) + Console.WriteLine(dateValue.ToString(fmt, dtfi)); + + Console.WriteLine(); + + // Modify the long date pattern. + dtfi.LongDatePattern = originalLongDatePattern + " g"; + foreach (var fmt in formats) + Console.WriteLine(dateValue.ToString(fmt, dtfi)); + + Console.WriteLine(); + + // Change A.D. to C.E. (for Common Era) + dtfi.LongDatePattern = originalLongDatePattern + @" 'C.E.'"; + foreach (var fmt in formats) + Console.WriteLine(dateValue.ToString(fmt, dtfi)); + } +} +// The example displays the following output: +// Saturday, May 18, 2013 +// Saturday, May 18, 2013 1:30 PM +// Saturday, May 18, 2013 1:30:00 PM +// +// Saturday, May 18, 2013 A.D. +// Saturday, May 18, 2013 A.D. 1:30 PM +// Saturday, May 18, 2013 A.D. 1:30:00 PM +// +// Saturday, May 18, 2013 C.E. +// Saturday, May 18, 2013 C.E. 1:30 PM +// Saturday, May 18, 2013 C.E. 1:30:00 PM +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs new file mode 100644 index 00000000000..e23c4454dad --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs @@ -0,0 +1,47 @@ +// +using System; +using System.Globalization; +using System.Text.RegularExpressions; + +public class Example5 +{ + public static void Main() + { + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + DateTimeFormatInfo dtfi = enUS.DateTimeFormat; + + Console.WriteLine("Original Property Values:"); + Console.WriteLine("ShortTimePattern: " + dtfi.ShortTimePattern); + Console.WriteLine("LongTimePattern: " + dtfi.LongTimePattern); + Console.WriteLine("FullDateTimePattern: " + dtfi.FullDateTimePattern); + Console.WriteLine(); + + dtfi.LongTimePattern = ReplaceWith24HourClock(dtfi.LongTimePattern); + dtfi.ShortTimePattern = ReplaceWith24HourClock(dtfi.ShortTimePattern); + + Console.WriteLine("Modififed Property Values:"); + Console.WriteLine("ShortTimePattern: " + dtfi.ShortTimePattern); + Console.WriteLine("LongTimePattern: " + dtfi.LongTimePattern); + Console.WriteLine("FullDateTimePattern: " + dtfi.FullDateTimePattern); + } + + private static string ReplaceWith24HourClock(string fmt) + { + string pattern = @"^(?\s*t+\s*)? " + + @"(?(openAMPM) h+(?[^ht]+)$ " + + @"| \s*h+(?[^ht]+)\s*t+)"; + return Regex.Replace(fmt, pattern, "HH${nonHours}", + RegexOptions.IgnorePatternWhitespace); + } +} +// The example displays the following output: +// Original Property Values: +// ShortTimePattern: h:mm tt +// LongTimePattern: h:mm:ss tt +// FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt +// +// Modififed Property Values: +// ShortTimePattern: HH:mm +// LongTimePattern: HH:mm:ss +// FullDateTimePattern: dddd, MMMM dd, yyyy HH:mm:ss +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs new file mode 100644 index 00000000000..1cdaa7e5fd9 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs @@ -0,0 +1,42 @@ +// +using System; +using System.Globalization; + +public class CurrentCultureFormatProvider : IFormatProvider +{ + public Object GetFormat(Type formatType) + { + Console.WriteLine($"Requesting an object of type {formatType.Name}"); + if (formatType == typeof(NumberFormatInfo)) + return NumberFormatInfo.CurrentInfo; + else if (formatType == typeof(DateTimeFormatInfo)) + return DateTimeFormatInfo.CurrentInfo; + else + return null; + } +} + +public class FormatProviderEx1 +{ + public static void Main() + { + DateTime dateValue = new DateTime(2013, 5, 28, 13, 30, 0); + string value = dateValue.ToString("F", new CurrentCultureFormatProvider()); + Console.WriteLine(value); + Console.WriteLine(); + string composite = String.Format(new CurrentCultureFormatProvider(), + "Date: {0:d} Amount: {1:C} Description: {2}", + dateValue, 1264.03m, "Service Charge"); + Console.WriteLine(composite); + Console.WriteLine(); + } +} +// The example displays output like the following: +// Requesting an object of type DateTimeFormatInfo +// Tuesday, May 28, 2013 1:30:00 PM +// +// Requesting an object of type ICustomFormatter +// Requesting an object of type DateTimeFormatInfo +// Requesting an object of type NumberFormatInfo +// Date: 5/28/2013 Amount: $1,264.03 Description: Service Charge +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs new file mode 100644 index 00000000000..fde2e0a0c06 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs @@ -0,0 +1,21 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx1 +{ + public static void Main() + { + DateTimeFormatInfo current1 = DateTimeFormatInfo.CurrentInfo; + current1 = (DateTimeFormatInfo)current1.Clone(); + Console.WriteLine(current1.IsReadOnly); + + CultureInfo culture2 = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name); + DateTimeFormatInfo current2 = culture2.DateTimeFormat; + Console.WriteLine(current2.IsReadOnly); + } +} +// The example displays the following output: +// False +// False +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs new file mode 100644 index 00000000000..5eb266248b6 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs @@ -0,0 +1,32 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx3 +{ + public static void Main() + { + CultureInfo culture; + DateTimeFormatInfo dtfi; + + culture = CultureInfo.CurrentCulture; + dtfi = culture.DateTimeFormat; + Console.WriteLine($"Culture Name: {culture.Name}"); + Console.WriteLine($"User Overrides: {culture.UseUserOverride}"); + Console.WriteLine($"Long Time Pattern: {culture.DateTimeFormat.LongTimePattern}\n"); + + culture = new CultureInfo(CultureInfo.CurrentCulture.Name, false); + Console.WriteLine($"Culture Name: {culture.Name}"); + Console.WriteLine($"User Overrides: {culture.UseUserOverride}"); + Console.WriteLine($"Long Time Pattern: {culture.DateTimeFormat.LongTimePattern}\n"); + } +} +// The example displays the following output: +// Culture Name: en-US +// User Overrides: True +// Long Time Pattern: HH:mm:ss +// +// Culture Name: en-US +// User Overrides: False +// Long Time Pattern: h:mm:ss tt +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs new file mode 100644 index 00000000000..2a1235fde35 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs @@ -0,0 +1,119 @@ +// +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; + +public class InstantiateEx6 +{ + public static void Main() + { + // Get all the neutral cultures + List names = new List(); + Array.ForEach(CultureInfo.GetCultures(CultureTypes.NeutralCultures), + culture => names.Add(culture.Name)); + names.Sort(); + foreach (var name in names) + { + // Ignore the invariant culture. + if (name == "") continue; + + ListSimilarChildCultures(name); + } + } + + private static void ListSimilarChildCultures(String name) + { + // Create the neutral DateTimeFormatInfo object. + DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo(name).DateTimeFormat; + // Retrieve all specific cultures of the neutral culture. + CultureInfo[] cultures = Array.FindAll(CultureInfo.GetCultures(CultureTypes.SpecificCultures), + culture => culture.Name.StartsWith(name + "-", StringComparison.OrdinalIgnoreCase)); + // Create an array of DateTimeFormatInfo properties + PropertyInfo[] properties = typeof(DateTimeFormatInfo).GetProperties(BindingFlags.Instance | BindingFlags.Public); + bool hasOneMatch = false; + + foreach (var ci in cultures) + { + bool match = true; + // Get the DateTimeFormatInfo for a specific culture. + DateTimeFormatInfo specificDtfi = ci.DateTimeFormat; + // Compare the property values of the two. + foreach (var prop in properties) + { + // We're not interested in the value of IsReadOnly. + if (prop.Name == "IsReadOnly") continue; + + // For arrays, iterate the individual elements to see if they are the same. + if (prop.PropertyType.IsArray) + { + IList nList = (IList)prop.GetValue(dtfi, null); + IList sList = (IList)prop.GetValue(specificDtfi, null); + if (nList.Count != sList.Count) + { + match = false; + Console.WriteLine($" Different n in {prop.Name} array for {name} and {ci.Name}"); + break; + } + + for (int ctr = 0; ctr < nList.Count; ctr++) + { + if (!nList[ctr].Equals(sList[ctr])) + { + match = false; + Console.WriteLine($" {prop.Name} value different for {name} and {ci.Name}"); + break; + } + } + + if (!match) break; + } + // Get non-array values. + else + { + Object specificValue = prop.GetValue(specificDtfi); + Object neutralValue = prop.GetValue(dtfi); + + // Handle comparison of Calendar objects. + if (prop.Name == "Calendar") + { + // The cultures have a different calendar type. + if (specificValue.ToString() != neutralValue.ToString()) + { + Console.WriteLine($" Different calendar types for {name} and {ci.Name}"); + match = false; + break; + } + + if (specificValue is GregorianCalendar) + { + if (((GregorianCalendar)specificValue).CalendarType != ((GregorianCalendar)neutralValue).CalendarType) + { + Console.WriteLine($" Different Gregorian calendar types for {name} and {ci.Name}"); + match = false; + break; + } + } + } + else if (!specificValue.Equals(neutralValue)) + { + match = false; + Console.WriteLine($" Different {prop.Name} values for {name} and {ci.Name}"); + break; + } + } + } + if (match) + { + Console.WriteLine($"DateTimeFormatInfo object for '{name}' matches '{ci.Name}'"); + hasOneMatch = true; + } + } + if (!hasOneMatch) + Console.WriteLine($"DateTimeFormatInfo object for '{name}' --> No Match"); + + Console.WriteLine(); + } +} +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs new file mode 100644 index 00000000000..d1a51b3cf63 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs @@ -0,0 +1,45 @@ +// +using System; +using System.Globalization; + +public class ParseEx1 +{ + public static void Main() + { + string[] dateStrings = { "08/18/2014", "01/02/2015" }; + string[] cultureNames = { "en-US", "en-GB", "fr-FR", "fi-FI" }; + + foreach (var cultureName in cultureNames) + { + CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName); + Console.WriteLine($"Parsing strings using the {culture.Name} culture."); + foreach (var dateStr in dateStrings) + { + try + { + Console.WriteLine(String.Format(culture, + " '{0}' --> {1:D}", dateStr, + DateTime.Parse(dateStr, culture))); + } + catch (FormatException) + { + Console.WriteLine($" Unable to parse '{dateStr}'"); + } + } + } + } +} +// The example displays the following output: +// Parsing strings using the en-US culture. +// '08/18/2014' --> Monday, August 18, 2014 +// '01/02/2015' --> Friday, January 02, 2015 +// Parsing strings using the en-GB culture. +// Unable to parse '08/18/2014' +// '01/02/2015' --> 01 February 2015 +// Parsing strings using the fr-FR culture. +// Unable to parse '08/18/2014' +// '01/02/2015' --> dimanche 1 février 2015 +// Parsing strings using the fi-FI culture. +// Unable to parse '08/18/2014' +// '01/02/2015' --> 1. helmikuuta 2015 +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs new file mode 100644 index 00000000000..3888b6215d9 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs @@ -0,0 +1,36 @@ +// +using System; +using System.Globalization; + +public class ParseEx2 +{ + public static void Main() + { + string inputDate = "14/05/10"; + + CultureInfo[] cultures = { CultureInfo.GetCultureInfo("en-US"), + CultureInfo.CreateSpecificCulture("en-US") }; + + foreach (var culture in cultures) + { + try + { + Console.WriteLine($"{culture.Name} culture reflects user overrides: {culture.UseUserOverride}"); + DateTime occasion = DateTime.Parse(inputDate, culture); + Console.WriteLine($"'{inputDate}' --> {occasion.ToString("D", CultureInfo.InvariantCulture)}"); + } + catch (FormatException) + { + Console.WriteLine($"Unable to parse '{inputDate}'"); + } + Console.WriteLine(); + } + } +} +// The example displays the following output: +// en-US culture reflects user overrides: False +// Unable to parse '14/05/10' +// +// en-US culture reflects user overrides: True +// '14/05/10' --> Saturday, 10 May 2014 +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj b/snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj new file mode 100644 index 00000000000..cb4ea68ebe3 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0 + enable + + + diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs new file mode 100644 index 00000000000..c7b73185d3f --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs @@ -0,0 +1,28 @@ +// +using System; +using System.Globalization; +using System.IO; + +public class SerializeEx1 +{ + public static void Main() + { + StreamWriter sw = new StreamWriter(@".\DateData.dat"); + // Define a date and time to serialize. + DateTime originalDate = new DateTime(2014, 08, 18, 08, 16, 35); + // Display information on the date and time. + Console.WriteLine($"Date to serialize: {originalDate:F}"); + Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}"); + Console.WriteLine($"Time Zone: {TimeZoneInfo.Local.DisplayName}"); + // Convert the date value to UTC. + DateTime utcDate = originalDate.ToUniversalTime(); + // Serialize the UTC value. + sw.Write(utcDate.ToString("o", DateTimeFormatInfo.InvariantInfo)); + sw.Close(); + } +} +// The example displays the following output: +// Date to serialize: Monday, August 18, 2014 8:16:35 AM +// Current Culture: en-US +// Time Zone: (UTC-08:00) Pacific Time (US & Canada) +// diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs new file mode 100644 index 00000000000..42e02b9c592 --- /dev/null +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs @@ -0,0 +1,29 @@ +// +using System; +using System.Globalization; +using System.IO; + +public class SerializeEx2 +{ + public static void Main() + { + // Open the file and retrieve the date string. + StreamReader sr = new StreamReader(@".\DateData.dat"); + String dateValue = sr.ReadToEnd(); + + // Parse the date. + DateTime parsedDate = DateTime.ParseExact(dateValue, "o", + DateTimeFormatInfo.InvariantInfo); + // Convert it to local time. + DateTime restoredDate = parsedDate.ToLocalTime(); + // Display information on the date and time. + Console.WriteLine($"Deserialized date: {restoredDate:F}"); + Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}"); + Console.WriteLine($"Time Zone: {TimeZoneInfo.Local.DisplayName}"); + } +} +// The example displays the following output: +// Deserialized date: lundi 18 août 2014 17:16:35 +// Current Culture: fr-FR +// Time Zone: (UTC+01:00) Brussels, Copenhagen, Madrid, Paris +// diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb new file mode 100644 index 00000000000..1a14275abd1 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb @@ -0,0 +1,42 @@ +' Visual Basic .NET Document +Option Infer On +Option Strict On + +' +Imports System.Globalization +Imports System.Threading + +Module Example1 + Public Sub S1() + Dim tasks As New List(Of Task) + Console.WriteLine("The current culture is {0}", + Thread.CurrentThread.CurrentCulture.Name) + Thread.CurrentThread.CurrentCulture = New CultureInfo("pt-BR") + ' Change the current culture to Portuguese (Brazil). + Console.WriteLine("Current culture changed to {0}", + Thread.CurrentThread.CurrentCulture.Name) + Console.WriteLine("Application thread is thread {0}", + Thread.CurrentThread.ManagedThreadId) + ' Launch six tasks and display their current culture. + For ctr As Integer = 0 To 5 + tasks.Add(Task.Run(Sub() + Console.WriteLine("Culture of task {0} on thread {1} is {2}", + Task.CurrentId, + Thread.CurrentThread.ManagedThreadId, + Thread.CurrentThread.CurrentCulture.Name) + End Sub)) + Next + Task.WaitAll(tasks.ToArray()) + End Sub +End Module +' The example displays output like the following: +' The current culture is en-US +' Current culture changed to pt-BR +' Application thread is thread 9 +' Culture of task 2 on thread 11 is pt-BR +' Culture of task 1 on thread 10 is pt-BR +' Culture of task 3 on thread 11 is pt-BR +' Culture of task 5 on thread 11 is pt-BR +' Culture of task 6 on thread 11 is pt-BR +' Culture of task 4 on thread 10 is pt-BR +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Get1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Get1.vb new file mode 100644 index 00000000000..6bc28fe84f8 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Get1.vb @@ -0,0 +1,16 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization + +Module Example3 + Public Sub S1() + Dim culture As CultureInfo = CultureInfo.CurrentCulture + Console.WriteLine("The current culture is {0} [{1}]", + culture.NativeName, culture.Name) + End Sub +End Module +' The example displays output like the following: +' The current culture is English (United States) [en-US] +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Program.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Program.vb new file mode 100644 index 00000000000..95f459e37e4 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Program.vb @@ -0,0 +1,5 @@ +Public Class Program + Public Shared Sub Main() + Example1.S1() + End Sub +End Class diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Project.vbproj b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Project.vbproj new file mode 100644 index 00000000000..f99395b4b2b --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Project.vbproj @@ -0,0 +1,8 @@ + + + + Exe + net10.0 + + + diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb new file mode 100644 index 00000000000..91257a0b53f --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb @@ -0,0 +1,23 @@ +' Visual Basic .NET Document +Option Strict On + +Imports System.Globalization +Imports System.Threading + +Module Example + Public Sub S1() + ' + Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0)) + ' + End Sub +End Module + + +Public Class Request + Private Shared langs(3) As String + Public Shared ReadOnly Property UserLanguages As String() + Get + Return langs + End Get + End Property +End Class diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb new file mode 100644 index 00000000000..59a55590241 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb @@ -0,0 +1,35 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization +Imports System.Threading + +Public Class Info : Inherits MarshalByRefObject + Public Sub ShowCurrentCulture() + Console.WriteLine("Culture of {0} in application domain {1}: {2}", + Thread.CurrentThread.Name, + AppDomain.CurrentDomain.FriendlyName, + CultureInfo.CurrentCulture.Name) + End Sub +End Class + +Module Example2 + Public Sub S1() + Dim inf As New Info() + ' Set the current culture to Dutch (Netherlands). + Thread.CurrentThread.Name = "MainThread" + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL") + inf.ShowCurrentCulture() + + ' Create a new application domain. + Dim ad As AppDomain = AppDomain.CreateDomain("Domain2") + Dim inf2 As Info = CType(ad.CreateInstanceAndUnwrap(GetType(Info).Assembly.FullName, "Info"), + Info) + inf2.ShowCurrentCulture() + End Sub +End Module +' This example displays the following output: +' Culture of MainThread in application domain Example.exe: nl-NL +' Culture of MainThread in application domain Domain2: nl-NL +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb new file mode 100644 index 00000000000..87380dd0c01 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb @@ -0,0 +1,30 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization +Imports System.Threading + +Module Example4 + Public Sub S1() + Dim value As Double = 1634.92 + CultureInfo.CurrentCulture = New CultureInfo("fr-CA") + Console.WriteLine("Current Culture: {0}", + CultureInfo.CurrentCulture.Name) + Console.WriteLine("{0:C2}", value) + Console.WriteLine() + + Thread.CurrentThread.CurrentCulture = New CultureInfo("fr") + Console.WriteLine("Current Culture: {0}", + CultureInfo.CurrentCulture.Name) + Console.WriteLine("{0:C2}", value) + End Sub +End Module +' The example displays the following output: +' Current Culture: fr-CA +' 1 634,92 $ +' +' Current Culture: fr +' 1 634,92 € +' + diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb new file mode 100644 index 00000000000..1b6cc161e69 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb @@ -0,0 +1,42 @@ +' Visual Basic .NET Document +Option Infer On +Option Strict On + +' +Imports System.Globalization +Imports System.Threading + +Module Example1 + Public Sub Main() + Dim tasks As New List(Of Task) + Console.WriteLine("The current UI culture is {0}", + Thread.CurrentThread.CurrentUICulture.Name) + Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-BR") + ' Change the current UI culture to Portuguese (Brazil). + Console.WriteLine("Current culture changed to {0}", + Thread.CurrentThread.CurrentUICulture.Name) + Console.WriteLine("Application thread is thread {0}", + Thread.CurrentThread.ManagedThreadId) + ' Launch six tasks and display their current culture. + For ctr As Integer = 0 To 5 + tasks.Add(Task.Run(Sub() + Console.WriteLine("Culture of task {0} on thread {1} is {2}", + Task.CurrentId, + Thread.CurrentThread.ManagedThreadId, + Thread.CurrentThread.CurrentUICulture.Name) + End Sub)) + Next + Task.WaitAll(tasks.ToArray()) + End Sub +End Module +' The example displays output like the following: +' The current culture is en-US +' Current culture changed to pt-BR +' Application thread is thread 9 +' Culture of task 2 on thread 11 is pt-BR +' Culture of task 1 on thread 10 is pt-BR +' Culture of task 3 on thread 11 is pt-BR +' Culture of task 5 on thread 11 is pt-BR +' Culture of task 6 on thread 11 is pt-BR +' Culture of task 4 on thread 10 is pt-BR +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb new file mode 100644 index 00000000000..96b9294dac3 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb @@ -0,0 +1,16 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization + +Module Example3 + Public Sub Main() + Dim culture As CultureInfo = CultureInfo.CurrentCulture + Console.WriteLine("The current UI culture is {0} [{1}]", + culture.NativeName, culture.Name) + End Sub +End Module +' The example displays output like the following: +' The current UI culture is English (United States) [en-US] +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Project.vbproj b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Project.vbproj new file mode 100644 index 00000000000..874c98f3477 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Project.vbproj @@ -0,0 +1,8 @@ + + + + Library + net10.0 + + + diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb new file mode 100644 index 00000000000..2dfafdb2692 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb @@ -0,0 +1,20 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization + +Module Example2 + Public Sub Main() + Console.WriteLine("The current UI culture: {0}", + CultureInfo.CurrentUICulture.Name) + + CultureInfo.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR") + Console.WriteLine("The current UI culture: {0}", + CultureInfo.CurrentUICulture.Name) + End Sub +End Module +' The example displays output like the following: +' The current UI culture: en-US +' The current UI culture: fr-FR +' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/Project.vbproj b/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/Project.vbproj new file mode 100644 index 00000000000..874c98f3477 --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/Project.vbproj @@ -0,0 +1,8 @@ + + + + Library + net10.0 + + + diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/persist1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/persist1.vb new file mode 100644 index 00000000000..cb6e6ef721d --- /dev/null +++ b/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/persist1.vb @@ -0,0 +1,53 @@ +' Visual Basic .NET Document +Option Strict On + +' +Imports System.Globalization +Imports System.IO + +Module Example + Public Sub Main() + ' Persist the date and time data. + Dim sw As New StreamWriter(".\DateData.dat") + + ' Create a DateTime value. + Dim dtIn As DateTime = DateTime.Now + ' Retrieve a CultureInfo object. + Dim invC As CultureInfo = CultureInfo.InvariantCulture + + ' Convert the date to a string and write it to a file. + sw.WriteLine(dtIn.ToString("r", invC)) + sw.Close() + + ' Restore the date and time data. + Dim sr As New StreamReader(".\DateData.dat") + Dim input As String = String.Empty + Do While sr.Peek() >= 0 + input = sr.ReadLine() + Console.WriteLine("Stored data: {0}" , input) + Console.WriteLine() + + ' Parse the stored string. + Dim dtOut As DateTime = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind) + + ' Create a French (France) CultureInfo object. + Dim frFr As New CultureInfo("fr-FR") + ' Displays the date formatted for the "fr-FR" culture. + Console.WriteLine("Date formatted for the {0} culture: {1}" , + frFr.Name, dtOut.ToString("f", frFr)) + + ' Creates a German (Germany) CultureInfo object. + Dim deDe As New CultureInfo("de-De") + ' Displays the date formatted for the "de-DE" culture. + Console.WriteLine("Date formatted for {0} culture: {1}" , + deDe.Name, dtOut.ToString("f", deDe)) + Loop + sr.Close() + End Sub +End Module +' The example displays the following output: +' Stored data: Tue, 15 May 2012 16:34:16 GMT +' +' Date formatted for the fr-FR culture: mardi 15 mai 2012 16:34 +' Date formatted for de-DE culture: Dienstag, 15. Mai 2012 16:34 +' diff --git a/xml/System.Globalization/CompareInfo.xml b/xml/System.Globalization/CompareInfo.xml index 2a45163860c..292b5d9f21f 100644 --- a/xml/System.Globalization/CompareInfo.xml +++ b/xml/System.Globalization/CompareInfo.xml @@ -84,9 +84,31 @@ ## Remarks - For more information about this API, see [Supplemental API remarks for CompareInfo](/dotnet/fundamentals/runtime-libraries/system-globalization-compareinfo). + Conventions for comparing and sorting data vary from culture to culture. For example, sort order may be based on phonetics or on the visual representation of characters. In East Asian languages, characters are sorted by the stroke and radical of ideographs. Sorting also depends on the order languages and cultures use for the alphabet. For example, the Danish language has an "Æ" character that it sorts after "Z" in the alphabet. In addition, comparisons may be case-sensitive or case-insensitive, and casing rules may also differ by culture. The class is responsible for maintaining this culture-sensitive string comparison data and for performing culture-sensitive string operations. - ## Example +Typically, you do not have to instantiate a object directly, because one is used implicitly by all non-ordinal string comparison operations, including calls to the method. However, if you do want to retrieve a object, you can do it in one of these ways: + +- By retrieving the value of the property for a particular culture. + +- By calling the static method with a culture name. This allows for late-bound access to a object. + +## Ignored search values + +Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. Comparison methods such as and do not consider such characters when they perform a culture-sensitive comparison. Ignorable characters include: + +- . Culture-sensitive comparison methods will always find an empty string at the beginning (index zero) of the string being searched. + +- A character or string consisting of characters with code points that are not considered in the operation because of comparison options, In particular, the and options produce searches in which symbols and nonspacing combining characters are ignored. + +- A string with code points that have no linguistic significance. For example, a soft hyphen (U+00AD) is always ignored in a culture-sensitive string comparison. + +## Security considerations + +If a security decision depends on a string comparison or a case change, you should use the property to ensure that the behavior is consistent, regardless of the culture settings of the operating system. + +> [!NOTE] +> When possible, you should use string comparison methods that have a parameter of type to specify the kind of comparison expected. As a general rule, use linguistic options (using the current culture) for comparing strings displayed in the user interface and specify or for security comparisons. +## Example The following example shows how the object associated with a object affects string comparison. diff --git a/xml/System.Globalization/CompareOptions.xml b/xml/System.Globalization/CompareOptions.xml index 83695e78a2a..5adfea83721 100644 --- a/xml/System.Globalization/CompareOptions.xml +++ b/xml/System.Globalization/CompareOptions.xml @@ -77,8 +77,18 @@ In .NET 5 and later, the cross-platform ICU (International Components for Unicod For more information about the change, including how to restore the previous Unicode handler, see [.NET globalization and ICU](/dotnet/core/extensions/globalization-icu). -For more information about this API, see [Supplemental API remarks for CompareOptions](/dotnet/fundamentals/runtime-libraries/system-globalization-compareoptions). +The options denote case sensitivity or necessity to ignore types of characters. +.NET uses three distinct ways of sorting: word sort, string sort, and ordinal sort. Word sort performs a culture-sensitive comparison of strings. Certain nonalphanumeric characters might have special weights assigned to them. For example, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. String sort is similar to word sort, except that there are no special cases. Therefore, all nonalphanumeric symbols come before all alphanumeric characters. Ordinal sort compares strings based on the Unicode values of each element of the string. For a downloadable set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, see [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921). For the sort weight table for Linux and macOS, see the [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt). The specific version of the sort weight table on Linux and macOS depends on the version of the [International Components for Unicode](https://icu.unicode.org/) libraries installed on the system. For information on ICU versions and the Unicode versions that they implement, see [Downloading ICU](https://icu.unicode.org/download). + +The `StringSort` value can only be used with and . is thrown if the StringSort value is used with , , , or . + +> [!NOTE] +> When possible, you should use string comparison methods that accept a value to specify the kind of comparison expected. As a general rule, user-facing comparisons are best served by the use of linguistic options (using the current culture), while security comparisons should specify `Ordinal` or `OrdinalIgnoreCase`. + +## Culture-sensitive sorts + +[!INCLUDE[platform-note](includes/c-and-posix-cultures.md)] ## Examples The following code example shows how each of the `CompareOptions` values affect string comparisons. diff --git a/xml/System.Globalization/CultureInfo.xml b/xml/System.Globalization/CultureInfo.xml index 4c11f4c43c7..313aa18fefd 100644 --- a/xml/System.Globalization/CultureInfo.xml +++ b/xml/System.Globalization/CultureInfo.xml @@ -83,9 +83,224 @@ ## Remarks - For more information about this API, see [Supplemental API remarks for CultureInfo](/dotnet/fundamentals/runtime-libraries/system-globalization-cultureinfo). + The class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the , , , and objects. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings. The class is used either directly or indirectly by classes that format, parse, or manipulate culture-specific data, such as , , , and the numeric types. - ## Example +## Culture names and identifiers + +The class specifies a unique name for each culture, based on RFC 4646. The name is a combination of an ISO 639 two-letter or three-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. In addition, for apps that are running under Windows 10 or later, culture names that correspond to valid BCP-47 language tags are supported. + +> [!NOTE] +> When a culture name is passed to a class constructor or a method such as or , its case is not significant. + +The format for the culture name based on RFC 4646 is *`languagecode2`*-*`country/regioncode2`*, where *`languagecode2`* is the two-letter language code and *`country/regioncode2`* is the two-letter subculture code. Examples include `ja-JP` for Japanese (Japan) and `en-US` for English (United States). In cases where a two-letter language code is not available, a three-letter code as defined in ISO 639-3 is used. + +Some culture names also specify an ISO 15924 script. For example, Cyrl specifies the Cyrillic script and Latn specifies the Latin script. A culture name that includes a script uses the pattern *`languagecode2`*-*`scripttag`*-*`country/regioncode2`*. An example of this type of culture name is `uz-Cyrl-UZ` for Uzbek (Cyrillic, Uzbekistan). On Windows operating systems before Windows Vista, a culture name that includes a script uses the pattern *`languagecode2`*-*`country/regioncode2`*-*`scripttag`*, for example, `uz-UZ-Cyrl` for Uzbek (Cyrillic, Uzbekistan). + +A neutral culture is specified by only the two-letter, lowercase language code. For example, `fr` specifies the neutral culture for French, and `de` specifies the neutral culture for German. + +> [!NOTE] +> There are two culture names that contradict this rule. The cultures Chinese (Simplified), named `zh-Hans`, and Chinese (Traditional), named `zh-Hant`, are neutral cultures. The culture names represent the current standard and should be used unless you have a reason for using the older names `zh-CHS` and `zh-CHT`. + +A culture identifier is a standard international numeric abbreviation and has the components necessary to uniquely identify one of the installed cultures. Your application can use predefined culture identifiers or define custom identifiers. + +Certain predefined culture names and identifiers are used by this and other classes in the namespace. For detailed culture information for Windows systems, see the **Language tag** column in the [list of language/region names supported by Windows](/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c). Culture names follow the standard defined by [BCP 47](https://tools.ietf.org/html/bcp47). + +The culture names and identifiers represent only a subset of cultures that can be found on a particular computer. Windows versions or service packs can change the available cultures. Applications can add custom cultures using the class. Users can add their own custom cultures using the [Microsoft Locale Builder](https://www.microsoft.com/download/details.aspx?id=41158) tool. Microsoft Locale Builder is written in managed code using the `CultureAndRegionInfoBuilder` class. + +Several distinct names are closely associated with a culture, notably the names associated with the following class members: + +- +- +- + +## Invariant, neutral, and specific cultures + +The cultures are generally grouped into three sets: invariant cultures, neutral cultures, and specific cultures. + +An invariant culture is culture-insensitive. Your application specifies the invariant culture by name using an empty string ("") or by its identifier. defines an instance of the invariant culture. It is associated with the English language but not with any country/region. It is used in almost any method in the `Globalization` namespace that requires a culture. + +A neutral culture is a culture that is associated with a language but not with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, `fr` is the neutral name for the French culture, and `fr-FR` is the name of the specific French (France) culture. Note that Chinese (Simplified) and Chinese (Traditional) are also considered neutral cultures. + +Creating an instance of a class for a neutral culture is not recommended because the data it contains is arbitrary. To display and sort data, specify both the language and region. Additionally, the property of a object created for a neutral culture returns only the country and does not include the region. + +The defined cultures have a hierarchy in which the parent of a specific culture is a neutral culture and the parent of a neutral culture is the invariant culture. The property contains the neutral culture associated with a specific culture. Custom cultures should define the property in conformance with this pattern. + +If the resources for a specific culture are not available in the operating system, the resources for the associated neutral culture are used. If the resources for the neutral culture are not available, the resources embedded in the main assembly are used. For more information on the resource fallback process, see [Packaging and Deploying Resources](/dotnet/framework/resources/packaging-and-deploying-resources-in-desktop-apps). + +The list of locales in the Windows API is slightly different from the list of cultures supported by .NET. If interoperability with Windows is required, for example, through the p/invoke mechanism, the application should use a specific culture that's defined for the operating system. Use of the specific culture ensures consistency with the equivalent Windows locale, which is identified with a locale identifier that is the same as . + +A or a can be created only for the invariant culture or for specific cultures, not for neutral cultures. + +If is the but the is not set to `zh-TW`, then , , and return an empty string (""). + +## Custom cultures + +On Windows, you can create custom locales. For more information, see [Custom locales](/windows/win32/intl/custom-locales). + +## CultureInfo and cultural data + +.NET derives its cultural data from a one of a variety of sources, depending on implementation, platform, and version: + +- In all versions of .NET (Core) running on Unix platforms or Windows 10 and later versions, cultural data is provided by the [International Components for Unicode (ICU) Library](https://icu.unicode.org/). The specific version of the ICU Library depends on the individual operating system. +- In all versions of .NET (Core) running on Windows 9 and earlier versions, cultural data is provided by the Windows operating system. +- In .NET Framework 4 and later versions, cultural data is provided by the Windows operating system. + +Because of this, a culture available on a particular .NET implementation, platform, or version may not be available on a different .NET implementation, platform, or version. + +Some `CultureInfo` objects differ depending on the underlying platform. In particular, `zh-CN`, or Chinese (Simplified, China) and `zh-TW`, or Chinese (Traditional, Taiwan), are available cultures on Windows systems, but they are aliased cultures on Unix systems. "zh-CN" is an alias for the "zh-Hans-CN" culture, and "zh-TW" is an alias for the "zh-Hant-TW" culture. Aliased cultures are not returned by calls to the method and may have different property values, including different cultures, than their Windows counterparts. For the `zh-CN` and `zh-TW` cultures, these differences include the following: + +- On Windows systems, the parent culture of the "zh-CN" culture is "zh-Hans", and the parent culture of the "zh-TW" culture is "zh-Hant". The parent culture of both these cultures is "zh". On Unix systems, the parents of both cultures are "zh". This means that, if you don't provide culture-specific resources for the "zh-CN" or "zh-TW" cultures but do provide a resources for the neutral "zh-Hans" or "zh-Hant" culture, your application will load the resources for the neutral culture on Windows but not on Unix. On Unix systems, you must explicitly set the thread's to either "zh-Hans" or "zh-Hant". + +- On Windows systems, calling on an instance that represents the "zh-CN" culture and passing it a "zh-Hans-CN" instance returns `true`. On Unix systems, the method call returns `false`. This behavior also applies to calling on a "zh-TW" instance and passing it a "zh-Hant-Tw" instance. + +## Dynamic culture data + +Except for the invariant culture, culture data is dynamic. This is true even for the predefined cultures. For example, countries or regions adopt new currencies, change their spellings of words, or change their preferred calendar, and culture definitions change to track this. Custom cultures are subject to change without notice, and any specific culture might be overridden by a custom replacement culture. Also, as discussed below, an individual user can override cultural preferences. Applications should always obtain culture data at runtime. + +> [!CAUTION] +> When saving data, your application should use the invariant culture, a binary format, or a specific culture-independent format. Data saved according to the current values associated with a particular culture, other than the invariant culture, might become unreadable or might change in meaning if that culture changes. + +## The current culture and current UI culture + +Every thread in a .NET application has a current culture and a current UI culture. The current culture determines the formatting conventions for dates, times, numbers, and currency values, the sort order of text, casing conventions, and the ways in which strings are compared. The current UI culture is used to retrieve culture-specific resources at runtime. + +> [!NOTE] +> For information on how the current and current UI culture is determined on a per-thread basis, see the [Culture and threads](#culture-and-threads) section. For information on how the current and current UI culture is determined on threads executing in a new application domain, and on threads that cross application domain boundaries, see the [Culture and application domains](#culture-and-application-domains) section. For information on how the current and current UI culture is determined on threads performing task-based asynchronous operations, see the [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations) section. + +For more detailed information on the current culture, see the property. For more detailed information on the current UI culture, see the property topic. + +### Retrieve the current and current UI cultures + +You can get a object that represents the current culture in either of two ways: + +- By retrieving the value of the property. +- By retrieving the value of the [Thread.CurrentThread.CurrentCulture]() property. + +The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Current1.cs" id="Snippet1"::: + +You can get a object that represents the current UI culture in either of two ways: + +- By retrieving the value of the property. + +- By retrieving the value of the [Thread.CurrentThread.CurrentUICulture]() property. + +The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current UI culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUI1.cs" id="Snippet2"::: + +### Set the current and current UI cultures + +To change the culture and UI culture of a thread, do the following: + +1. Instantiate a object that represents that culture by calling a class constructor and passing it the name of the culture. The constructor instantiates a object that reflects user overrides if the new culture is the same as the current Windows culture. The constructor allows you to specify whether the newly instantiated object reflects user overrides if the new culture is the same as the current Windows culture. + +2. Assign the object to the or property on .NET Core and .NET Framework 4.6 and later versions. + +The following example retrieves the current culture. If it is anything other than the French (France) culture, it changes the current culture to French (France). Otherwise, it changes the current culture to French (Luxembourg). + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Change1.cs" id="Snippet3"::: + +The following example retrieves the current culture. If it is anything other the Slovenian (Slovenia) culture, it changes the current culture to Slovenian (Slovenia). Otherwise, it changes the current culture to Croatian (Croatia). + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/ChangeUI1.cs" id="Snippet4"::: + +## Get all cultures + +You can retrieve an array of specific categories of cultures or of all the cultures available on the local computer by calling the method. For example, you can retrieve custom cultures, specific cultures, or neutral cultures either alone or in combination. + +The following example calls the method twice, first with the enumeration member to retrieve all custom cultures, and then with the enumeration member to retrieve all replacement cultures. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/GetCultures1.cs" id="Snippet5"::: + +## Culture and threads + +When a new application thread is started, its current culture and current UI culture are defined by the current system culture, and not by the current thread culture. The following example illustrates the difference. It sets the current culture and current UI culture of an application thread to the French (France) culture (fr-FR). If the current culture is already fr-FR, the example sets it to the English (United States) culture (en-US). It displays three random numbers as currency values and then creates a new thread, which, in turn, displays three more random numbers as currency values. But as the output from the example shows, the currency values displayed by the new thread do not reflect the formatting conventions of the French (France) culture, unlike the output from the main application thread. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/defaultthread1.cs" id="Snippet1"::: + +You can set the culture and UI culture of all threads in an application domain by assigning a object that represents that culture to the and properties. The following example uses these properties to ensure that all threads in the default application domain share the same culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/setthreads1.cs" id="Snippet3"::: + +> [!WARNING] +> Although the and properties are static members, they define the default culture and default UI culture only for the application domain that is current at the time these property values are set. For more information, see the next section, [Culture and application domains](#culture-and-application-domains). + +When you assign values to the and properties, the culture and UI culture of the threads in the application domain also change if they have not explicitly been assigned a culture. However, these threads reflect the new culture settings only while they execute in the current application domain. If these threads execute in another application domain, their culture becomes the default culture defined for that application domain. As a result, we recommend that you always set the culture of the main application thread, and not rely on the and properties to change it. + +## Culture and application domains + + and are static properties that explicitly define a default culture only for the application domain that is current when the property value is set or retrieved. The following example sets the default culture and default UI culture in the default application domain to French (France), and then uses the class and the delegate to set the default culture and UI culture in a new application domain to Russian (Russia). A single thread then executes two methods in each application domain. Note that the thread's culture and UI culture are not explicitly set; they are derived from the default culture and UI culture of the application domain in which the thread is executing. Note also that the and properties return the default values of the application domain that is current when the method call is made. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/appdomainex1.cs" id="Snippet1"::: + +For more information about cultures and application domains, see the "Application Domains and Threads" section in the [Application Domains](/dotnet/framework/app-domains/application-domains) topic. + +## Culture and task-based asynchronous operations + +The [task-based asynchronous programming pattern](/dotnet/standard/parallel-programming/task-based-asynchronous-programming) uses and objects to asynchronously execute delegates on thread pool threads. The specific thread on which a particular task runs is not known in advance, but is determined only at runtime. + +For apps that target .NET Framework 4.6 or a later version, culture is part of an asynchronous operation's context. In other words, asynchronous operations by default inherit the values of the and properties of the thread from which they are launched. If the current culture or current UI culture differs from the system culture, the current culture crosses thread boundaries and becomes the current culture of the thread pool thread that is executing an asynchronous operation. + +The following example provides a simple illustration. The example defines a delegate, `formatDelegate`, that returns some numbers formatted as currency values. The example changes the current system culture to either French (France) or, if French (France) is already the current culture, English (United States). It then: + +- Invokes the delegate directly so that it runs synchronously on the main app thread. +- Creates a task that executes the delegate asynchronously on a thread pool thread. +- Creates a task that executes the delegate synchronously on the main app thread by calling the method. + +As the output from the example shows, when the current culture is changed to French (France), the current culture of the thread from which tasks are invoked asynchronously becomes the current culture for that asynchronous operation. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/asyncculture1.cs" id="Snippet1"::: + + and are per-app domain properties; that is, they establish a default culture for all threads not explicitly assigned a culture in a specific application domain. However, for apps that target .NET Framework 4.6 or later, the culture of the calling thread remains part of an asynchronous task's context even if the task crosses app domain boundaries. + +## CultureInfo object serialization + +When a object is serialized, all that is actually stored is and . It is successfully deserialized only in an environment where that has the same meaning. The following three examples show why this is not always the case: + +- If the property value is , and if that culture was first introduced in a particular version of the Windows operating system, it is not possible to deserialize it on an earlier version of Windows. For example, if a culture was introduced in Windows 10, it cannot be deserialized on Windows 8. + +- If the value is , and the computer on which it is deserialized does not have this user custom culture installed, it is not possible to deserialize it. + +- If the value is , and the computer on which it is deserialized does not have this replacement culture, it deserializes to the same name, but not all of the same characteristics. For example, if `en-US` is a replacement culture on computer A, but not on computer B, and if a object referring to this culture is serialized on computer A and deserialized on computer B, then none of the custom characteristics of the culture are transmitted. The culture deserializes successfully, but with a different meaning. + +## Control Panel overrides + +The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. In general, your applications should honor these user overrides. + +If is `true` and the specified culture matches the current culture of Windows, the uses those overrides, including user settings for the properties of the instance returned by the property, and the properties of the instance returned by the property. If the user settings are incompatible with the culture associated with the , for example, if the selected calendar is not one of the , the results of the methods and the values of the properties are undefined. + +## Alternate sort orders + +Some cultures support more than one sort order. For example: + +- The Spanish (Spain) culture has two sort orders: the default international sort order, and the traditional sort order. When you instantiate a object with the `es-ES` culture name, the international sort order is used. When you instantiate a object with the `es-ES-tradnl` culture name, the traditional sort order is used. + +- The `zh-CN` (Chinese (Simplified, PRC)) culture supports two sort orders: by pronunciation (the default) and by stroke count. When you instantiate a object with the `zh-CN` culture name, the default sort order is used. When you instantiate a object with a local identifier of 0x00020804, strings are sorted by stroke count. + +The following table lists the cultures that support alternate sort orders and the identifiers for the default and alternate sort orders. + +|Culture name|Culture|Default sort name and identifier|Alternate sort name and identifier| +|------------------|-------------|--------------------------------------|----------------------------------------| +|es-ES|Spanish (Spain)|International: 0x00000C0A|Traditional: 0x0000040A| +|zh-TW|Chinese (Taiwan)|Stroke Count: 0x00000404|Bopomofo: 0x00030404| +|zh-CN|Chinese (PRC)|Pronunciation: 0x00000804|Stroke Count: 0x00020804| +|zh-HK|Chinese (Hong Kong SAR)|Stroke Count: 0x00000c04|Stroke Count: 0x00020c04| +|zh-SG|Chinese (Singapore)|Pronunciation: 0x00001004|Stroke Count: 0x00021004| +|zh-MO|Chinese (Macao SAR)|Pronunciation: 0x00001404|Stroke Count: 0x00021404| +|ja-JP|Japanese (Japan)|Default: 0x00000411|Unicode: 0x00010411| +|ko-KR|Korean (Korea)|Default: 0x00000412|Korean Xwansung - Unicode: 0x00010412| +|de-DE|German (Germany)|Dictionary: 0x00000407|Phone Book Sort DIN: 0x00010407| +|hu-HU|Hungarian (Hungary)|Default: 0x0000040e|Technical Sort: 0x0001040e| +|ka-GE|Georgian (Georgia)|Traditional: 0x00000437|Modern Sort: 0x00010437| + +## The current culture and UWP apps + +In Universal Windows Platform (UWP) apps, the and properties are read-write, just as they are in .NET Framework and .NET Core apps. However, UWP apps recognize a single culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. + +In .NET apps, the current culture is a per-thread setting, and the and properties reflect the culture and UI culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection, which is a global setting. Setting the or property changes the culture of the entire app; culture cannot be set on a per-thread basis. +## Example The following example shows how to create a object for Spanish (Spain) with the international sort and another object with the traditional sort. @@ -915,7 +1130,87 @@ If `name` is , the constr Gets or sets the object that represents the culture used by the current thread and task-based asynchronous operations. The culture used by the current thread and task-based asynchronous operations. - For more information about this API, see Supplemental API remarks for CultureInfo.CurrentCulture. + + object that's returned by the property and its associated objects determines the default format for dates, times, numbers, and currency values, the sorting order of text, casing conventions, and string comparisons. + +The current culture is a property of the executing thread. When you set this property to a object that represents a new culture, the value of the `Thread.CurrentThread.CurrentCulture` property also changes. However, we recommend that you always use the property to retrieve and set the current culture. + +The `CultureInfo` object that this property returns is read-only. That means you can't mutate the existing object, for example, by changing the `DateTimeFormat`. To change the date-time format or some other aspect of the current culture, create a new `CultureInfo` object and assign it to the property. + +## How a thread's culture is determined + +When a thread is started, its culture is initially determined as follows: + +- By retrieving the culture that is specified by the property in the application domain in which the thread is executing, if the property value is not `null`. + +- If the thread is a thread pool thread that is executing a task-based asynchronous operation, its culture is determined by the culture of the calling thread. The following example changes the current culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current culture. Each of the tasks (and the threads) has inherited the culture of the calling thread. + + :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb" id="Snippet14"::: + + For more information, see [Culture and task-based asynchronous operations](system-globalization-cultureinfo.md#culture-and-task-based-asynchronous-operations). + +- By calling the `GetUserDefaultLocaleName` function on Windows or the `uloc_getDefault` function from [ICU](https://icu-project.org/), which currently calls the POSIX `setlocale` function with category `LC_MESSAGES`, on Unix-like systems. + +Note that if you set a specific culture that is different from the system-installed culture or the user's preferred culture, and your application starts multiple threads, the current culture of those threads will be the culture that is returned by the `GetUserDefaultLocaleName` function, unless you assign a culture to the property in the application domain in which the thread is executing. + +For more information about how the culture of a thread is determined, see the "Culture and threads" section in the reference page. + +## Get the current culture + +The property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the property, as the following example illustrates. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs" id="Snippet5"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Get1.vb" id="Snippet5"::: + +## Set the CurrentCulture property explicitly + +To change the culture that's used by an existing thread, you set the property to the new culture. If you explicitly change a thread's culture in this way, that change persists if the thread crosses application domain boundaries. The following example changes the current thread culture to Dutch (Netherlands). It also shows that, when the current thread crosses application domain boundaries, its current culture remains changed. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs" id="Snippet11"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb" id="Snippet11"::: + +> [!NOTE] +> Changing the culture by using the property requires a permission with the value set. Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code. + +Starting with .NET Framework 4, you can explicitly change the current thread culture to either a specific culture (such as French (Canada)) or a neutral culture (such as French). When a object represents a neutral culture, the values of properties such as , , , , and reflect the specific culture that is associated with the neutral culture. For example, the dominant culture for the English neutral culture is English (United States); the dominant culture for the German culture is German (Germany). The following example illustrates the difference in formatting when the current culture is set to a specific culture, French (Canada), and a neutral culture, French. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs" id="Snippet12"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb" id="Snippet12"::: + +You can also use the property along with the property to set the property of an ASP.NET application to the user's preferred culture, as the following example illustrates. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs" id="Snippet13"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb" id="Snippet13"::: + +## The current culture and user overrides + +Windows allows users to override the standard property values of the object and its associated objects by using **Regional and Language Options** in Control Panel. The object returned by the property reflects these user overrides in the following cases: + +- If the current thread culture is set implicitly by the Windows `GetUserDefaultLocaleName` function. + +- If the current thread culture defined by the property corresponds to the current Windows system culture. + +- If the current thread culture is set explicitly to a culture returned by the method, and that culture corresponds to the current Windows system culture. + +- If the current thread culture is set explicitly to a culture instantiated by the constructor, and that culture corresponds to the current Windows system culture. + +In some cases, particularly for server applications, setting the current culture to a object that reflects user overrides may be undesirable. Instead, you can set the current culture to a object that does not reflect user overrides in the following ways: + +- By calling the constructor with a value of `false` for the `useUserOverride` argument. + +- By calling the method, which returns a cached, read-only object. + +## The current culture and UWP apps + +In Universal Windows Platform (UWP) apps, the property is read-write, just as it is in .NET Framework and .NET Core apps; you can use it both to get and to set the current culture. However, UWP apps do not distinguish between the current culture and the current UI culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. + +In .NET Framework and .NET Core apps, the current culture is a per-thread setting, and the property reflects the culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) property, which is a global setting. Setting the property changes the culture of the entire app; culture cannot be set on a per-thread basis. + + ]]> + and of the current thread. @@ -979,7 +1274,71 @@ The following example demonstrates how to change the Gets or sets the object that represents the current user interface culture used by the Resource Manager to look up culture-specific resources at run time. The culture used by the Resource Manager to look up culture-specific resources at run time. - For more information about this API, see Supplemental API remarks for CultureInfo.CurrentUICulture. + + property is a per-thread property. That is, each thread has its own current UI culture. This property is equivalent to retrieving or setting the object assigned to the `System.Threading.Thread.CurrentThread.CurrentUICulture` property. When a thread is started, its UI culture is initially determined as follows: + +- By retrieving the culture that is specified by the property in the application domain in which the thread is executing, if the property value is not `null`. + +- If the thread is a thread pool thread that is executing a task-based asynchronous operation and the app targets the .NET Framework 4.6 or a later version of the .NET Framework, its UI culture is determined by the UI culture of the calling thread. The following example changes the current UI culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current UI culture. Each of the tasks (and the threads) has inherited the UI culture of the calling thread. + + :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb" id="Snippet14"::: + + For more information, see the "Culture and task-based asynchronous operations" section in the documentation. + +- By calling the Windows `GetUserDefaultUILanguage` function. + +To change the user interface culture used by a thread, set the property to the new culture. If you explicitly change a thread's UI culture in this way, that change persists if the thread crosses application domain boundaries. + +> [!NOTE] +> If you set the property value to a object that represents a new culture, the value of the `Thread.CurrentThread.CurrentCulture` property also changes. + +## Get the current UI culture + +The property is a per-thread setting; that is, each thread can have its own UI culture. You get the UI culture of the current thread by retrieving the value of the property, as the following example illustrates. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Get1.cs" id="Snippet5"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb" id="Snippet5"::: + +You can also retrieve the value of the current thread's UI culture from the property. + +## Explicitly set the current UI culture + +Starting with .NET Framework 4.6, you can change the current UI culture by assigning a object that represents the new culture to the property. The current UI culture can be set to either a specific culture (such as en-US or de-DE) or to a neutral culture (such as en or de). The following example sets the current UI culture to fr-FR or French (France). + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb" id="Snippet1"::: + +In a multithreaded application, you can explicitly set the UI culture of any thread by assigning a object that represents that culture to the thread's property. If the thread whose culture you want to set is the current thread, you can assign the new culture to the property. When the UI culture of a thread is set explicitly, that thread retains the same culture even if it crosses application domain boundaries and executes code in another application domain. + +## Implicitly set the current UI culture + +When a thread, including the main application thread, is first created, by default its current UI culture is set as follows: + +- By using the culture defined by the property for the current application domain if the property value is not `null`. +- By using the system's default culture. On systems that use the Windows operating system, the common language runtime calls the Windows `GetUserDefaultUILanguage` function to set the current UI culture. `GetUserDefaultUILanguage` returns the default UI culture set by the user. If the user has not set a default UI language, it returns the culture originally installed on the system. + +If the thread crosses application boundaries and executes code in another application domain, its culture is determined in the same way as that of a newly created thread. + +Note that if you set a specific UI culture that is different from the system-installed UI culture or the user's preferred UI culture, and your application starts multiple threads, the current UI culture of those threads will be the culture returned by the `GetUserDefaultUILanguage` function, unless you assign a culture to the property in the application domain in which the thread is executing. + +## Security considerations + +Changing the culture of the current thread requires a permission with the value set. + +> [!CAUTION] +> Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code. + +## The current UI culture and UWP apps + +In Universal Windows Platform (UWP) apps, the property is read-write, just as it is in .NET Framework and .NET Core apps; you can use it both to get and to set the current culture. However, UWP apps do not distinguish between the current culture and the current UI culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. + +In .NET Framework and .NET Core apps, the current UI culture is a per-thread setting, and the property reflects the UI culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) property, which is a global setting. Setting the property changes the culture of the entire app; culture cannot be set on a per-thread basis. + + ]]> + and of the current thread. @@ -2373,7 +2732,34 @@ Setting `predefinedOnly` to `true` will ensure a culture is created only if the Gets the object that is culture-independent (invariant). The object that is culture-independent (invariant). - For more information about this API, see Supplemental API remarks for CultureInfo.InvariantCulture. + + instantiation method. This property, , also retrieves an instance of the invariant culture. It can be used in almost any method in the namespace that requires a culture. The objects returned by properties such as , , and also reflect the string comparison and formatting conventions of the invariant culture. + +Unlike culture-sensitive data, which is subject to change by user customization or by updates to the .NET Framework or the operating system, invariant culture data is stable over time and across installed cultures and cannot be customized by users. This makes the invariant culture particularly useful for operations that require culture-independent results, such as formatting and parsing operations that persist formatted data, or sorting and ordering operations that require that data be displayed in a fixed order regardless of culture. + +## String operations + +You can use the invariant culture for culture-sensitive string operations that are not affected by the conventions of the current culture and that are consistent across cultures. For example, you may want sorted data to appear in a fixed order or apply a standard set of casing conventions to strings regardless of the current culture. To do this, you pass the object to a method that has a parameter, such as and . + +## Persisting data + +The property can be used to persist data in a culture-independent format. This provides a known format that does not change and that can be used to serialize and deserialize data across cultures. After the data is deserialized, it can be formatted appropriately based on the cultural conventions of the current user. + +For example, if you choose to persist date and time data in string form, you can pass the object to the or method to create the string, and you can pass the object to the or method to convert the string back to a date and time value. This technique ensures that the underlying date and time values do not change when the data is read or written by users from different cultures. + +The following example uses the invariant culture to persist a value as a string. It then parses the string and displays its value by using the formatting conventions of the French (France) and German (Germany) cultures. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/InvariantCulture/persist1.cs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/InvariantCulture/persist1.vb" id="Snippet1"::: + +## Security decisions + +If you are making a security decision (such as whether to allow access to a system resource) based on the result of a string comparison or a case change, you should not use the invariant culture. Instead, you should perform a case-sensitive or case-insensitive ordinal comparison by calling a method that includes a parameter and supplying either or as an argument. Code that performs culture-sensitive string operations can cause security vulnerabilities if the current culture is changed or if the culture on the computer that is running the code differs from the culture that is used to test the code. In contrast, an ordinal comparison depends solely on the binary value of the compared characters. + + ]]> + diff --git a/xml/System.Globalization/DateTimeFormatInfo.xml b/xml/System.Globalization/DateTimeFormatInfo.xml index 041838113a5..ed9380c6d42 100644 --- a/xml/System.Globalization/DateTimeFormatInfo.xml +++ b/xml/System.Globalization/DateTimeFormatInfo.xml @@ -78,7 +78,364 @@ Provides culture-specific information about the format of date and time values. - For more information about this API, see Supplemental API remarks for DateTimeFormatInfo. + + class contain culture-specific information for formatting or parsing date and time values such as the following: + +- The patterns used to format date values. +- The patterns used to format time values. +- The names of the days of the week. +- The names of the months of the year. +- The A.M. and P.M. designators used in time values. +- The calendar in which dates are expressed. + +## Instantiate a DateTimeFormatInfo object + +A object can represent the formatting conventions of the invariant culture, a specific culture, a neutral culture, or the current culture. This section discusses how to instantiate each type of object. + +### Instantiate a DateTimeFormatInfo object for the invariant culture + +The invariant culture represents a culture that is culture-insensitive. It is based on the English language, but not on any specific English-speaking country/region. Although the data of specific cultures can be dynamic and can change to reflect new cultural conventions or user preferences, the data of the invariant culture does not change. You can instantiate a object that represents the formatting conventions of the invariant culture in the following ways: + +- By retrieving the value of the property. The returned object is read-only. +- By calling the parameterless constructor. The returned object is read/write. +- By retrieving the value of the property from the object that is returned by the property. The returned object is read-only. + +The following example uses each of these methods to instantiate a object that represents the invariant culture. It then indicates whether the object is read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet1"::: + +### Instantiate a DateTimeFormatInfo object for a specific culture + +A specific culture represents a language that is spoken in a particular country/region. For example, en-US is a specific culture that represents the English language spoken in the United States, and en-CA is a specific culture that represents the English language spoken in Canada. You can instantiate a object that represents the formatting conventions of a specific culture in the following ways: + +- By calling the method and retrieving the value of the returned object's property. The returned object is read-only. + +- By passing the static method a object that represents the culture whose object you want to retrieve. The returned object is read/write. + +- By calling the static method and retrieving the value of the returned object's property. The returned object is read/write. + +- By calling the class constructor and retrieving the value of the returned object's property. The returned object is read/write. + +The following example illustrates each of these ways to instantiate a object and indicates whether the resulting object is read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet3"::: + +### Instantiate a DateTimeFormatInfo object for a neutral culture + +A neutral culture represents a culture or language that is independent of a country/region; it is typically the parent of one or more specific cultures. For example, Fr is a neutral culture for the French language and the parent of the fr-FR culture. You can instantiate a object that represents the formatting conventions of a neutral culture in the same ways that you create a object that represents the formatting conventions of a specific culture. In addition, you can retrieve a neutral culture's object by retrieving a neutral culture from a specific culture's property and retrieving the object returned by its property. Unless the parent culture represents the invariant culture, the returned object is read/write. The following example illustrates these ways of instantiating a object that represents a neutral culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet2"::: + +However, a neutral culture lacks culture-specific formatting information, because it is independent of a specific country/region. Instead of populating the object with generic values, .NET returns a object that reflects the formatting conventions of a specific culture that is a child of the neutral culture. For example, the object for the neutral en culture reflects the formatting conventions of the en-US culture, and the object for the fr culture reflects the formatting conventions of the fr-FR culture. + +You can use code like the following to determine which specific culture's formatting conventions a neutral culture represents. The example uses reflection to compare the properties of a neutral culture with the properties of a specific child culture. It considers two calendars to be equivalent if they are the same calendar type and, for Gregorian calendars, if their properties have identical values. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs" id="Snippet6"::: + +### Instantiate a DateTimeFormatInfo object for the current culture + +You can instantiate a object that represents the formatting conventions of the current culture in the following ways: + +- By retrieving the value of the property. The returned object is read-only. + +- By retrieving the value of the property from the object that is returned by the property. The returned object is read-only. + +- By calling the method with a object that represents the current culture. The returned object is read-only. + +The following example uses each of these methods to instantiate a object that represents the formatting conventions of the current culture. It then indicates whether the object is read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs" id="Snippet4"::: + +You can create a writable object that represents the conventions of the current culture in one of these ways: + +- By retrieving a object in any of the three previous ways and calling the method on the returned object. This creates a copy of the original object, except that its property is `false`. + +- By calling the method to create a object that represents the current culture, and then using its property to retrieve the object. + +The following example illustrates each way of instantiating a read/write object and displays the value of its property. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs" id="Snippet7"::: + +In Windows, the user can override some of the property values used in formatting and parsing operations through the **Region and Language** application in Control Panel. For example, a user whose culture is English (United States) might choose to display long time values using a 24-hour clock (in the format HH:mm:ss) instead of the default 12-hour clock (in the format h:mm:ss tt). The objects retrieved in the ways discussed previously all reflect these user overrides. If this is undesirable, you can create a object that does not reflect user overrides (and is also read/write instead of read-only) by calling the constructor and supplying a value of `false` for the `useUserOverride` argument. The following example illustrates this for a system whose current culture is English (United States) and whose long time pattern has been changed from the default of h:mm:ss tt to HH:mm:ss. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs" id="Snippet8"::: + +## DateTimeFormatInfo and dynamic data + +The culture-specific data for formatting date and time values provided by the class is dynamic, just like cultural data provided by the class. You should not make any assumptions about the stability of values for objects that are associated with particular objects. Only the data provided by the invariant culture and its associated object is stable. Other data can change between application sessions or even while your application is running. There are four major sources of change: + +- System updates. Cultural preferences such as the preferred calendar or customary date and time formats change over time. When this happens, Windows Update includes changes to the property value for a particular culture. + +- Replacement cultures. The class can be used to replace the data of an existing culture. + +- Cascading changes to property values. A number of culture-related properties can change at runtime, which, in turn, causes data to change. For example, the current culture can be changed either programmatically or through user action. When this happens, the object returned by the property changes to an object associated with the current culture. Similarly, a culture's calendar can change, which can result in changes to numerous property values. + +- User preferences. Users of your application might choose to override some of the values associated with the current system culture through the regional and language options in Control Panel. For example, users might choose to display the date in a different format. If the property is set to `true`, the properties of the object is also retrieved from the user settings. If the user settings are incompatible with the culture associated with the object (for example, if the selected calendar is not one of the calendars indicated by the property), the results of the methods and the values of the properties are undefined. + +To minimize the possibility of inconsistent data, all user-overridable properties of a object are initialized when the object is created. There is still a possibility of inconsistency, because neither object creation nor the user override process is atomic and the relevant values can change during object creation. However, this situation should be extremely rare. + +You can control whether user overrides are reflected in objects that represent the same culture as the system culture. The following table lists the ways in which a object can be retrieved and indicates whether the resulting object reflects user overrides. + +|Source of CultureInfo and DateTimeFormatInfo object|Reflects user overrides| +|---------------------------------------------------------|-----------------------------| +|`CultureInfo.CurrentCulture.DateTimeFormat` property|Yes| +| property|Yes| +| method|Yes| +| method|No| +| constructor|Yes| +| constructor|Depends on value of `useUserOverride` parameter| + +Unless there is a compelling reason to do otherwise, you should respect user overrides when you use the object in client applications to format and parse user input or to display data. For server applications or unattended applications, you should not. However, if you are using the object either explicitly or implicitly to persist date and time data in string form, you should either use a object that reflects the formatting conventions of the invariant culture, or you should specify a custom date and time format string that you use regardless of culture. + +## Format dates and times + +A object is used implicitly or explicitly in all date and time formatting operations. These include calls to the following methods: + +- All date and time formatting methods, such as and . +- The major composite formatting method, which is . +- Other composite formatting methods, such as and . + +All date and time formatting operations make use of an implementation. The interface includes a single method, . This callback method is passed a object that represents the type needed to provide formatting information. The method returns either an instance of that type or `null` if it cannot provide an instance of the type. .NET includes two implementations for formatting dates and times: + +- The class, which represents a specific culture (or a specific language in a specific country/region). In a date and time formatting operation, the method returns the object associated with its property. +- The class, which provides information about the formatting conventions of its associated culture. The method returns an instance of itself. + +If an implementation is not provided to a formatting method explicitly, the object returned by the property that represents the current culture is used. + +The following example illustrates the relationship between the interface and the class in formatting operations. It defines a custom implementation whose method displays the type of the object requested by the formatting operation. If it is requesting a object, the method provides the object for the current culture. As the output from the example shows, the method requests a object to provide formatting information, whereas the method requests and objects as well as an implementation. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs" id="Snippet9"::: + +## Format strings and DateTimeFormatInfo properties + +The object includes three kinds of properties that are used in formatting operations with date and time values: + +- Calendar-related properties. Properties such as , , , and , are associated with the calendar used by the culture, which is defined by the property. These properties are used for long date and time formats. + +- Properties that produce a standards-defined result string. The , , and properties contain custom format strings that produce result strings defined by international standards. These properties are read-only and cannot be modified. + +- Properties that define culture-sensitive result strings. Some properties, such as and , contain [custom format strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) that specify the format of the result string. Others, such as , , , and , define culture-sensitive symbols or substrings that can be included in a result string. + +The [standard date and time format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings), such as "d", "D", "f", and "F", are aliases that correspond to particular format pattern properties. Most of the [custom date and time format strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) are related to strings or substrings that a formatting operation inserts into the result stream. The following table lists the standard and custom date and time format specifiers and their associated properties. For details about how to use these format specifiers, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). Note that each standard format string corresponds to a property whose value is a custom date and time format string. The individual specifiers in this custom format string in turn correspond to other properties. The table lists only the properties for which the standard format strings are aliases, and does not list properties that may be accessed by custom format strings assigned to those aliased properties. In addition, the table lists only custom format specifiers that correspond to properties. + +|Format specifier|Associated properties| +|----------------------|---------------------------| +|"d" (short date; standard format string)|, to define the overall format of the result string.| +|"D" (long date; standard format string)|, to define the overall format of the result string.| +|"f" (full date / short time; standard format string)|, to define the format of the date component of the result string.

, to define the format of the time component of the result string.| +|"F" (full date / long time; standard format string)|, to define the format of the date component of the result string.

, to define the format of the time component of the result string.| +|"g" (general date / short time; standard format string)|, to define the format of the date component of the result string.

, to define the format of the time component of the result string.| +|"G" (general date / long time; standard format string)|, to define the format of the date component of the result string.

, to define the format of the time component of the result string.| +|"M", "m" (month/day; standard format string)|, to define the overall format of the result string.| +|"O", "o" (round-trip date/time; standard format string)|None.| +|"R", "r" (RFC1123; standard format string)|, to define a result string that conforms to the RFC 1123 standard. The property is read-only.| +|"s" (sortable date/time; standard format string)|, to define a result string that conforms to the ISO 8601 standard. The property is read-only.| +|"t" (short time; standard format string)|, to define the overall format of the result string.| +|"T" (long time; standard format string)|, to define the overall format of the result string.| +|"u" (universal sortable date/time; standard format string)|, to define a result string that conforms to the ISO 8601 standard for coordinated universal time. The property is read-only.| +|"U" (universal full date/time; standard format string)|, to define the overall format of the result string.| +|"Y", "y" (year month; standard format string)|, to define the overall format of the result string.| +|"ddd" (custom format specifier)|, to include the abbreviated name of the day of the week in the result string.| +|"g", "gg" (custom format specifier)|Calls the method to insert the era name in the result string.| +|"MMM" (custom format specifier)| or , to include the abbreviated month name in the result string.| +|"MMMM" (custom format specifier)| or , to include the full month name in the result string.| +|"t" (custom format specifier)| or , to include the first character of the AM/PM designator in the result string.| +|"tt" (custom format specifier)| or , to include the full AM/PM designator in the result string.| +|":" (custom format specifier)|, to include the time separator in the result string.| +|"/" (custom format specifier)|, to include the date separator in the result string.| + +## Modify DateTimeFormatInfo properties + +You can change the result string produced by date and time format strings by modifying the associated properties of a writable object. To determine if a object is writable, use the property. To customize a object in this way: + +1. Create a read/write copy of a object whose formatting conventions you want to modify. + +2. Modify the property or properties that are used to produce the desired result string. (For information about how formatting methods use properties to define result strings, see the previous section, [Format strings and DateTimeFormatInfo properties](#format-strings-and-datetimeformatinfo-properties).) + +3. Use the custom object you created as the argument in calls to formatting methods. + +There are two other ways to change the format of a result string: + +- You can use the class to define either a custom culture (a culture that has a unique name and that supplements existing cultures) or a replacement culture (one that is used instead of a specific culture). You can save and access this culture programmatically as you would any object supported by .NET. + +- If the result string is not culture-sensitive and doesn't follow a predefined format, you can use a custom date and time format string. For example, if you are serializing date and time data in the format YYYYMMDDHHmmss, you can generate the result string by passing the custom format string to the method, and you can convert the result string back to a value by calling the method. + +### Change the short date pattern + +The following example changes the format of a result string produced by the "d" (short date) standard format string. It changes the associated property for the en-US or English (United States) culture from its default of "M/d/yyyy" to "yyyy'-"MM"-"dd" and uses the "d" standard format string to display the date both before and after the property is changed. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs" id="Snippet10"::: + +### Change the date separator character + +The following example changes the date separator character in a object that represents the formatting conventions of the fr-FR culture. The example uses the "g" standard format string to display the date both before and after the property is changed. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs" id="Snippet12"::: + +### Change day name abbreviations and the long date pattern + +In some cases, the long date pattern, which typically displays the full day and month name along with the number of the day of the month and the year, may be too long. The following example shortens the long date pattern for the en-US culture to return a one-character or two-character day name abbreviation followed by the day number, the month name abbreviation, and the year. It does this by assigning shorter day name abbreviations to the array, and by modifying the custom format string assigned to the property. This affects the result strings returned by the "D" and "f" standard format strings. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs" id="Snippet13"::: + +Ordinarily, the change to the property also affects the property, which in turn defines the result string returned by the "F" standard format string. To preserve the original full date and time pattern, the example reassigns the original custom format string assigned to the property after the property is modified. + +### Change from a 12-hour clock to a 24-hour clock + +For many cultures in .NET, the time is expressed by using a 12-hour clock and an AM/PM designator. The following example defines a `ReplaceWith24HourClock` method that replaces any time format that uses a 12-hour clock with a format that uses a 24-hour clock. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs" id="Snippet14"::: + +The example uses a regular expression to modify the format string. The regular expression pattern `@"^(?\s*t+\s*)? (?(openAMPM) h+(?[^ht]+)$ | \s*h+(?[^ht]+)\s*t+)` is defined as follows: + +|Pattern|Description| +|-------------|-----------------| +|`^`|Begin the match at the beginning of the string.| +|`(?\s*t+\s*)?`|Match zero or one occurrence of zero or more white-space characters, followed by the letter "t" one or more times, followed by zero or more white-space characters. This capturing group is named `openAMPM`.| +|`(?(openAMPM) h+(?[^ht]+) + + + + + + + + + + + + + System.Globalization + 4.0.0.0 + 4.0.10.0 + + + mscorlib + 1.0.5000.0 + 2.0.0.0 + 2.0.5.0 + 4.0.0.0 + + + netstandard + 2.0.0.0 + 2.1.0.0 + + + System.Runtime + 4.2.0.0 + 4.2.1.0 + 4.2.2.0 + 5.0.0.0 + 6.0.0.0 + 7.0.0.0 + 8.0.0.0 + 9.0.0.0 + 10.0.0.0 + 11.0.0.0 + + + + + + + + + + + + + + + + + + + + + + System.Object + + + + System.ICloneable + + + System.IFormatProvider + + + + + [System.Runtime.CompilerServices.Nullable(0)] + [<System.Runtime.CompilerServices.Nullable(0)>] + + + + Provides culture-specific information about the format of date and time values. +|If the `openAMPM` group has a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t". The match ends at the end of the string. All characters captured after "h" are included in a capturing group named `nonHours`.| +|`| \s*h+(?[^ht]+)\s*t+)`|If the `openAMPM` group does not have a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t", followed by zero or more white-space characters. Finally, match one or more occurrences of the letter "t". All characters captured after "h" and before the white-spaces and "t" are included in a capturing group named `nonHours`.| + +The `nonHours` capturing group contains the minute and possibly the second component of a custom date and time format string, along with any time separator symbols. The replacement pattern `HH${nonHours}` prepends the substring "HH" to these elements. + +### Display and change the era in a date + +The following example adds the "g" custom format specifier to the property of an object that represents the formatting conventions of the en-US culture. This addition affects the following three standard format strings: + +- The "D" (long date) standard format string, which maps directly to the property. + +- The "f" (full date / short time) standard format string, which produces a result string that concatenates the substrings produced by the and properties. + +- The "F" (full date / long time) standard format string, which maps directly to the property. Because we have not explicitly set this property value, it is generated dynamically by concatenating the and properties. + +The example also shows how to change the era name for a culture whose calendar has a single era. In this case, the en-US culture uses the Gregorian calendar, which is represented by a object. The class supports a single era, which it names A.D. (Anno Domini). The example changes the era name to C.E. (Common Era) by replacing the "g" custom format specifier in the format string assigned to the property with a literal string. The use of a literal string is necessary, because the era name is typically returned by the method from private data in the culture tables supplied by either .NET or the operating system. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs" id="Snippet11"::: + +## Parse date and time strings + +Parsing involves converting the string representation of a date and time to a or value. Both of these types include the `Parse`, `TryParse`, `ParseExact`, and `TryParseExact` methods to support parsing operations. The `Parse` and `TryParse` methods convert a string that can have a variety of formats, whereas `ParseExact` and `TryParseExact` require that the string have a defined format or formats. If the parsing operation fails, `Parse` and `ParseExact` throw an exception, whereas `TryParse` and `TryParseExact` return `false`. + +The parsing methods implicitly or explicitly use a enumeration value to determine which style elements (such as leading, trailing, or inner white space) can be present in the string to be parsed, and how to interpret the parsed string or any missing elements. If you don't provide a value when you call the `Parse` or `TryParse` method, the default is , which is a composite style that includes the , , and flags. For the `ParseExact` and `TryParseExact` methods, the default is ; the input string must correspond precisely to a particular custom date and time format string. + +The parsing methods also implicitly or explicitly use a object that defines the specific symbols and patterns that can occur in the string to be parsed. If you don't provide a object, the object for the current culture is used by default. For more information about parsing date and time strings, see the individual parsing methods, such as , , , and . + +The following example illustrates the culture-sensitive nature of parsing date and time strings. It tries to parse two date strings by using the conventions of the en-US, en-GB, fr-FR, and fi-FI cultures. The date that is interpreted as 8/18/2014 in the en-US culture throws a exception in the other three cultures because 18 is interpreted as the month number. 1/2/2015 is parsed as the second day of the first month in the en-US culture, but as the first day of the second month in the remaining cultures. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs" id="Snippet15"::: + +Date and time strings are typically parsed for two reasons: + +- To convert user input into a date and time value. +- To round-trip a date and time value; that is, to deserialize a date and time value that was previously serialized as a string. + +The following sections discuss these two operations in greater detail. + +### Parse user strings + +When you parse date and time strings input by the user, you should always instantiate a object that reflects the user's cultural settings, including any customizations the user may have made. Otherwise, the date and time object may have incorrect values. For information about how to instantiate a object that reflects user cultural customizations, see the [DateTimeFormatInfo and dynamic data](#datetimeformatinfo-and-dynamic-data) section. + +The following example illustrates the difference between a parsing operation that reflects user cultural settings and one that does not. In this case, the default system culture is en-US, but the user has used Control Panel, **Region and Language** to change the short date pattern from its default of "M/d/yyyy" to "yy/MM/dd". When the user enters a string that reflects user settings, and the string is parsed by a object that also reflects user settings (overrides), the parsing operation returns a correct result. However, when the string is parsed by a object that reflects standard en-US cultural settings, the parsing method throws a exception because it interprets 14 as the number of the month, not the last two digits of the year. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs" id="Snippet16"::: + +### Serialize and deserialize date and time data + +Serialized date and time data are expected to round-trip; that is, all serialized and deserialized values should be identical. If a date and time value represents a single moment in time, the deserialized value should represent the same moment in time regardless of the culture or time zone of the system on which it was restored. To round-trip date and time data successfully, you must use the conventions of the invariant culture, which is returned by the property, to generate and parse the data. The formatting and parsing operations should never reflect the conventions of the default culture. If you use default cultural settings, the portability of the data is strictly limited; it can be successfully deserialized only on a thread whose cultural-specific settings are identical to those of the thread on which it was serialized. In some cases, this means that the data cannot even be successfully serialized and deserialized on the same system. + +If the time component of a date and time value is significant, it should also be converted to UTC and serialized by using the "o" or "r" [standard format string](/dotnet/standard/base-types/standard-date-and-time-format-strings). The time data can then be restored by calling a parsing method and passing it the appropriate format string along with the invariant culture as the `provider` argument. + +The following example illustrates the process of round-tripping a date and time value. It serializes a date and time on a system that observes U.S. Pacific time and whose current culture is en-US. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs" id="Snippet17"::: + +It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Paris time zone and whose current culture is fr-FR. The restored date is nine hours later than the original date, which reflects the time zone adjustment from eight hours behind UTC to one hour ahead of UTC. Both the original date and the restored date represent the same moment in time. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs" id="Snippet18"::: + + ]]>
+
class contains culture-specific information that is used when you format and parse numeric values. This information includes the currency symbol, the decimal symbol, the group separator symbol, and the symbols for positive and negative signs. - ## Example +## Instantiate a NumberFormatInfo object + +You can instantiate a object that represents the formatting conventions of the current culture, the invariant culture, a specific culture, or a neutral culture. + +### Instantiate a NumberFormatInfo object for the current culture + +You can instantiate a object for the current culture in any of the following ways. In each case, the returned object is read-only. + +- By retrieving a object that represents the current culture from the property, and retrieving the object from its property. + +- By retrieving the object returned by the `static` (`Shared` in Visual Basic) property. + +- By calling the method with a object that represents the current culture. + +The following example uses these three ways to create objects that represent the formatting conventions of the current culture. It also retrieves the value of the property to illustrate that each object is read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate1.cs" id="Snippet1"::: + +You can create a writable object that represents the conventions of the current culture in any of the following ways: + +- By retrieving a object in any of the ways illustrated in the previous code example, and calling the method on the returned object. This creates a copy of the original object, except that its property is `false`. + +- By calling the method to create a object that represents the current culture, and then using its property to retrieve the object. + +The following example illustrates these two ways of instantiating a object, and displays the value of its property to illustrate that the object is not read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate2.cs" id="Snippet2"::: + +Note that the Windows operating system allows the user to override some of the property values used in numeric formatting and parsing operations through the **Region and Language** item in Control Panel. For example, a user whose culture is English (United States) might choose to display currency values as 1.1 USD instead of the default of $1.1. The objects retrieved in the ways discussed previously all reflect these user overrides. If this is undesirable, you can create a object that does not reflect user overrides (and that is also read/write rather than read-only) by calling the constructor and supplying a value of `false` for the `useUserOverride` argument. The following example provides an illustration for a system whose current culture is English (United States) and whose currency symbol has been changed from the default of $ to USD. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate3.cs" id="Snippet3"::: + +If the property is set to `true`, the properties , , and are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the object (for example, if the selected calendar is not one of the calendars listed by the property), the results of the methods and the values of the properties are undefined. + +### Instantiate a NumberFormatInfo object for the invariant culture + +The invariant culture represents a culture that is culture-insensitive. It is based on the English language but not on any specific English-speaking country/region. Although the data of specific cultures can be dynamic and can change to reflect new cultural conventions or user preferences, the data of the invariant culture does not change. A object that represents the formatting conventions of the invariant culture can be used for formatting operations in which result strings should not vary by culture. + +You can instantiate a object that represents the formatting conventions of the invariant culture in the following ways: + +- By retrieving the value of the property. The returned object is read-only. + +- By retrieving the value of the property from the object that is returned by the property. The returned object is read-only. + +- By calling the parameterless class constructor. The returned object is read/write. + +The following example uses each of these methods to instantiate a object that represents the invariant culture. It then indicates whether the object is read-only, + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate4.cs" id="Snippet4"::: + +### Instantiate a NumberFormatInfo object for a specific culture + +A specific culture represents a language that is spoken in a particular country/region. For example, en-US is a specific culture that represents the English language spoken in the United States, and en-CA is a specific culture that represents the English language spoken in Canada. You can instantiate a object that represents the formatting conventions of a specific culture in the following ways: + +- By calling the method and retrieving the value of the returned object's property. The returned object is read-only. + +- By passing a object that represents the culture whose object you want to retrieve to the static method. The returned object is read/write. + +- By calling the method and retrieving the value of the returned object's property. The returned object is read/write. + +- By calling one of the class constructors and retrieving the value of the returned object's property. The returned object is read/write. + +The following example uses these four ways to create a object that reflects the formatting conventions of the Indonesian (Indonesia) culture. It also indicates whether each object is read-only. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate5.cs" id="Snippet5"::: + +### Instantiate a NumberFormatInfo object for a neutral culture + +A neutral culture represents a culture or language that is independent of a country/region. It is typically the parent of one or more specific cultures. For example, fr is a neutral culture for the French language and the parent of the fr-FR culture. You create a object that represents the formatting conventions of a neutral culture in the same way that you create a object that represents the formatting conventions of a specific culture. + +However, because it is independent of a specific country/region, a neutral culture lacks culture-specific formatting information. Rather than populating the object with generic values, .NET returns a object that reflects the formatting conventions of a specific culture that is a child of the neutral culture. For example, the object for the neutral en culture reflects the formatting conventions of the en-US culture, and the object for the fr culture reflects the formatting conventions of the fr-FR culture. + +You can use code like the following to determine which specific culture's formatting conventions each neutral culture represents. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate6.cs" id="Snippet6"::: + +## Dynamic data + +The culture-specific data for formatting numeric values provided by the class is dynamic, just like the cultural data provided by the class. You should not make any assumptions about the stability of values for objects that are associated with particular objects. Only the data provided by the invariant culture and its associated object is stable. Other data can change between application sessions, or even within a single session, for the following reasons: + +- **System updates.** Cultural preferences such as the currency symbol or currency formats change over time. When this happens, Windows Update includes changes to the property value for a particular culture. + +- **Replacement cultures.** The class can be used to replace the data of an existing culture. + +- **Cascading changes to property values.** A number of culture-related properties can change at runtime, which, in turn, causes data to change. For example, the current culture can be changed either programmatically or through user action. When this happens, the object returned by the property changes to an object associated with the current culture. + +- **User preferences.** Users of your application might override some of the values associated with the current system culture through the region and language options in Control Panel. For example, users might choose a different currency symbol or a different decimal separator symbol. If the property is set to `true` (its default value), the properties of the object are also retrieved from the user settings. + +All user-overridable properties of a object are initialized when the object is created. There is still a possibility of inconsistency, because neither object creation nor the user override process is atomic, and the relevant values may change during object creation. However, these inconsistencies should be extremely rare. + +You can control whether user overrides are reflected in objects that represent the same culture as the current culture. The following table lists the ways in which a object can be retrieved and indicates whether the resulting object reflects user overrides. + +|Source of CultureInfo and NumberFormatInfo object|Reflects user overrides| +|-------------------------------------------------------|-----------------------------| +|`CultureInfo.CurrentCulture.NumberFormat` property|Yes| +| property|Yes| +| method|Yes| +| method|No| +| constructor|Yes| +| constructor|Depends on value of `useUserOverride` parameter| + +Unless there is a compelling reason to do otherwise, you should respect user overrides when you use the object in client applications to format and parse user input or to display numeric data. For server applications or unattended applications, you should not respect user overrides. However, if you are using the object either explicitly or implicitly to persist numeric data in string form, you should either use a object that reflects the formatting conventions of the invariant culture, or you should specify a custom numeric format string that you use regardless of culture. + +## IFormatProvider, NumberFormatInfo, and numeric formatting + +A object is used implicitly or explicitly in all numeric formatting operations. These include calls to the following methods: + +- All numeric formatting methods, such as , , and . + +- The major composite formatting method, . + +- Other composite formatting methods, such as and . + +All numeric formatting operations make use of an implementation. The interface includes a single method, . This is a callback method that is passed a object that represents the type needed to provide formatting information. The method is responsible for returning either an instance of that type or `null`, if it cannot provide an instance of the type. .NET provides two implementations for formatting numbers: + +- The class, which represents a specific culture (or a specific language in a specific country/region). In a numeric formatting operation, the method returns the object associated with its property. + +- The class, which provides information about the formatting conventions of its associated culture. The method returns an instance of itself. + +If an implementation is not provided to a formatting method explicitly, a object returned by the property that represents the current culture is used. + +The following example illustrates the relationship between the interface and the class in formatting operations by defining a custom implementation. Its method displays the type name of the object requested by the formatting operation. If the interface is requesting a object, this method provides the object for the current culture. As the output from the example shows, the method requests a object to provide formatting information, whereas the method requests and objects as well as an implementation. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/formatprovider1.cs" id="Snippet1"::: + +If an implementation is not explicitly provided in a numeric formatting method call, the method calls the `CultureInfo.CurrentCulture.GetFormat` method, which returns the object that corresponds to the current culture. + +## Format strings and NumberFormatInfo properties + +Every formatting operation uses either a standard or a custom numeric format string to produce a result string from a number. In some cases, the use of a format string to produce a result string is explicit, as in the following example. This code calls the method to convert a value to a number of different string representations by using the formatting conventions of the en-US culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/properties1.cs" id="Snippet2"::: + +In other cases, the use of a format string is implicit. For example, in the following method calls to the default or parameterless method, the value of the instance is formatted by using the general ("G") format specifier and the conventions of the current culture, which in this case is the en-US culture. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/properties2.cs" id="Snippet3"::: + +Each standard numeric format string uses one or more properties to determine the pattern or the symbols used in the result string. Similarly, each custom numeric format specifier except "0" and "#" insert symbols in the result string that are defined by properties. The following table lists the standard and custom numeric format specifiers and their associated properties. To change the appearance of the result string for a particular culture, see the [Modify NumberFormatInfo properties](#modify-numberformatinfo-properties) section. For details about the use of these format specifiers, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). + +|Format specifier|Associated properties| +|----------------------|---------------------------| +|"C" or "c" (currency format specifier)|, to define the default number of fractional digits.

, to define the decimal separator symbol.

, to define the group or thousands separator.

, to define the sizes of integral groups.

, to define the pattern of negative currency values.

, to define the pattern of positive currency values.

, to define the currency symbol.

, to define the negative sign symbol.| +|"D" or "d" (decimal format specifier)|, to define the negative sign symbol.| +|"E" or "e" (exponential or scientific format specifier)|, to define the negative sign symbol in the mantissa and exponent.

, to define the decimal separator symbol.

, to define the positive sign symbol in the exponent.| +|"F" or "f" (fixed-point format specifier)|, to define the negative sign symbol.

, to define the default number of fractional digits.

, to define the decimal separator symbol.| +|"G" or "g" (general format specifier)|, to define the negative sign symbol.

, to define the decimal separator symbol.

, to define the positive sign symbol for result strings in exponential format.| +|"N" or "n" (number format specifier)|, to define the negative sign symbol.

, to define the default number of fractional digits.

, to define the decimal separator symbol.

, to define the group separator (thousands) symbol.

, to define the number of integral digits in a group.

, to define the format of negative values.| +|"P" or "p" (percent format specifier)|, to define the negative sign symbol.

, to define the default number of fractional digits.

, to define the decimal separator symbol.

, to define the group separator symbol.

, to define the number of integral digits in a group.

, to define the placement of the percent symbol and the negative symbol for negative values.

, to define the placement of the percent symbol for positive values.

, to define the percent symbol.| +|"R" or "r" (round-trip format specifier)|, to define the negative sign symbol.

, to define the decimal separator symbol.

, to define the positive sign symbol in an exponent.| +|"X" or "x" (hexadecimal format specifier)|None.| +|"." (decimal point custom format specifier)|, to define the decimal separator symbol.| +|"," (group separator custom format specifier)|, to define the group (thousands) separator symbol.| +|"%" (percentage placeholder custom format specifier)|, to define the percent symbol.| +|"‰" (per mille placeholder custom format specifier)|, to define the per mille symbol.| +|"E" (exponential notation custom format specifier)|, to define the negative sign symbol in the mantissa and exponent.

, to define the positive sign symbol in the exponent.| + +Note that the class includes a property that specifies the base 10 digits used by a specific culture. However, the property is not used in formatting operations; only the Basic Latin digits 0 (U+0030) through 9 (U+0039) are used in the result string. In addition, for and values of `NaN`, `PositiveInfinity`, and `NegativeInfinity`, the result string consists exclusively of the symbols defined by the , , and properties, respectively. + +## Modify NumberFormatInfo properties + +You can modify the properties of a object to customize the result string produced in a numeric formatting operation. To do this: + +1. Create a read/write copy of a object whose formatting conventions you want to modify. For more information, see the [Instantiate a NumberFormatInfo object](#instantiate-a-numberformatinfo-object) section. + +2. Modify the property or properties that are used to produce the desired result string. For information about how formatting methods use properties to define result strings, see the [Format strings and NumberFormatInfo properties](#format-strings-and-numberformatinfo-properties) section. + +3. Use the custom object as the argument in calls to formatting methods. + +> [!NOTE] +> Instead of dynamically modifying a culture's property values each time an application is started, you can use the class to define either a custom culture (a culture that has a unique name and that supplements existing cultures) or a replacement culture (one that is used instead of a specific culture). + +The following sections provide some examples. + +### Modify the currency symbol and pattern + +The following example modifies a object that represents the formatting conventions of the en-US culture. It assigns the ISO-4217 currency symbol to the property and defines a pattern for currency values that consists of the currency symbol followed by a space and a numeric value. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/customize_currency1.cs" id="Snippet1"::: + +### Format a national identification number + +Many national identification numbers consist exclusively of digits and so can easily be formatted by modifying the properties of a object. For example, a social security number in the United States consists of 9 digits arranged as follows: `XXX-XX-XXXX`. The following example assumes that social security numbers are stored as integer values and formats them appropriately. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/customize_ssn1.cs" id="Snippet2"::: + +## Parse numeric strings + +Parsing involves converting the string representation of a number to a number. Each numeric type in .NET includes two overloaded parsing methods: `Parse` and `TryParse`. The `Parse` method converts a string to a number and throws an exception if the conversion fails. The `TryParse` method converts a string to a number, assigns the number to an `out` argument, and returns a value that indicates whether the conversion succeeded. + +The parsing methods implicitly or explicitly use a enumeration value to determine what style elements (such as group separators, a decimal separator, or a currency symbol) can be present in a string if the parsing operation is to succeed. If a value is not provided in the method call, the default is a value that includes the and flags, which specifies that the parsed string can include group symbols, a decimal separator, a negative sign, and white-space characters, or it can be the string representation of a number in exponential notation. + +The parsing methods also implicitly or explicitly use a object that defines the specific symbols and patterns that can occur in the string to be parsed. If a object is not provided, the default is the for the current culture. For more information about parsing, see the individual parsing methods, such as , , , , , and . + +The following example illustrates the culture-sensitive nature of parsing strings. It tries to parse a string that include thousands separators by using the conventions of the en-US, fr-FR, and invariant cultures. A string that includes the comma as a group separator and the period as a decimal separator fails to parse in the fr-FR culture, and a string with white space as a group separator and a comma as a decimal separator fails to parse in the en-US and invariant cultures. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/parse1.cs" id="Snippet4"::: + +Parsing generally occurs in two contexts: + +- As an operation that is designed to convert user input into a numeric value. + +- As an operation that is designed to round-trip a numeric value; that is, to deserialize a numeric value that was previously serialized as a string. + +The following sections discuss these two operations in greater detail. + +### Parse user strings + +When you are parsing numeric strings input by the user, you should always instantiate a object that reflects the user's cultural settings. For information about how to instantiate a object that reflects user customizations, see the [Dynamic data](#dynamic-data) section. + +The following example illustrates the difference between a parsing operation that reflects user cultural settings and one that does not. In this case, the default system culture is en-US, but the user has defined "," as the decimal symbol and "." as the group separator in Control Panel, **Region and Language**. Ordinarily, these symbols are reversed in the default en-US culture. When the user enters a string that reflects user settings, and the string is parsed by a object that also reflects user settings (overrides), the parsing operation returns a correct result. However, when the string is parsed by a object that reflects standard en-US cultural settings, it mistakes the comma symbol for a group separator and returns an incorrect result. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/parseuser1.cs" id="Snippet5"::: + +### Serialize and deserialize numeric data + +When numeric data is serialized in string format and later deserialized and parsed, the strings should be generated and parsed by using the conventions of the invariant culture. The formatting and parsing operations should never reflect the conventions of a specific culture. If culture-specific settings are used, the portability of the data is strictly limited; it can be successfully deserialized only on a thread whose culture-specific settings are identical to those of the thread on which it was serialized. In some cases, this means that the data cannot even be successfully deserialized on the same system on which it was serialized. + +The following example illustrates what can happen when this principle is violated. Floating-point values in an array are converted to strings when the current thread uses the culture-specific settings of the en-US culture. +The data is then parsed by a thread that uses the culture-specific settings of the pt-BR culture. In this case, although each parsing operation succeeds, the data doesn't round-trip successfully and data corruption occurs. +In other cases, a parsing operation could fail and a exception could be thrown. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/parsepersisted.cs" id="Snippet6"::: +## Example The following example shows how to retrieve a object for a corresponding object, and use the retrieved object to query number formatting information for the particular culture. diff --git a/xml/System.Globalization/PersianCalendar.xml b/xml/System.Globalization/PersianCalendar.xml index 37009761b88..56cdef675fb 100644 --- a/xml/System.Globalization/PersianCalendar.xml +++ b/xml/System.Globalization/PersianCalendar.xml @@ -65,7 +65,38 @@ Represents the Persian calendar. - For more information about this API, see Supplemental API remarks for PersianCalendar. + + [!NOTE] +> For information about using the class and the other calendar classes in .NET, see [Working with Calendars](/dotnet/standard/datetime/working-with-calendars). + +The Persian calendar is a solar Hijri calendar, and starts from the year of the Hijra, which corresponds to 622 C.E. the year when Muhammad (PBUH) migrated from Mecca to Medina. + +The Persian calendar is based on a solar year and is approximately 365 days long. A year cycles through four seasons, and a new year begins when the sun appears to cross the equator from the southern hemisphere to the northern hemisphere as viewed from the center of the Earth. The new year marks the first day of the month of Farvardeen, which is the first day of spring in the northern hemisphere. For example, the date March 21, 2002 C.E. corresponds to the first day of the month of Farvardeen in the year 1381 Anno Persico. + +Each of the first six months in the Persian calendar has 31 days, each of the next five months has 30 days, and the last month has 29 days in a common year and 30 days in a leap year. A leap year is a year that, when divided by 33, has a remainder of 1, 5, 9, 13, 17, 22, 26, or 30. For example, the year 1370 is a leap year because dividing it by 33 yields a remainder of 17. There are approximately eight leap years in every 33-year cycle. + +## The PersianCalendar class and .NET versions + +Starting with .NET Framework 4.6, the class uses the Hijri solar astronomical algorithm rather than an observational algorithm to calculate dates. This makes the implementation consistent with the Persian calendar in use in Iran and Afghanistan, the two countries in which the Persian calendar is in most widespread use. The change affects all apps running on .NET Framework 4 or later if .NET Framework 4.6 is installed. + +As a result of the changed algorithm: + +- The two algorithms should return identical results when converting dates between 1800 and 2123 in the Gregorian calendar. +- The two algorithms might return different results when converting dates before 1800 and after 2123 in the Gregorian calendar. +- The property value has changed from March 21, 0622 in the Gregorian calendar to March 22, 0622 in the Gregorian calendar. +- The property value has changed from the 10th day of the 10th month of the year 9378 in the Persian calendar to the 13th day of the 10th month of the year 9378 in the Persian calendar. +- The method might return a different result than it did previously. + +## Use the PersianCalendar class + +You can use a object to calculate dates in the Persian calendar or convert Persian dates to and from Gregorian dates. The Persian calendar is the [default calendar](xref:System.Globalization.CultureInfo.Calendar) for cultures such as Persian (Afghanistan) and Central Kurdish (Iran). + + ]]> + objects by using the property, a constructor, and the Persian calendar's method. It then displays these dates in both the Gregorian and Persian calendars. It also displays the date range of the Persian calendar. diff --git a/xml/System.Globalization/RegionInfo.xml b/xml/System.Globalization/RegionInfo.xml index cd14546f38a..a53528621cf 100644 --- a/xml/System.Globalization/RegionInfo.xml +++ b/xml/System.Globalization/RegionInfo.xml @@ -71,9 +71,35 @@ ## Remarks - For more information about this API, see [Supplemental API remarks for RegionInfo](/dotnet/fundamentals/runtime-libraries/system-globalization-regioninfo). + Unlike the class, the class does not represent user preferences and does not depend on the user's language or culture. - ## Example +## Names associated with a RegionInfo object + +The name of a object is one of the two-letter codes defined in ISO 3166 for country/region. Case is not significant. The , , and properties return the appropriate codes in uppercase. For the current list of names, see [ISO 3166: Country codes](https://www.iso.org/iso-3166-country-codes.html). + +## Instantiate a RegionInfo object + +To instantiate a object, you pass the constructor either a two-letter region name, such as "US" for the United States, or the name of a specific culture, such as "en-US" for English (United States). However, we recommend that you use a specific culture name instead of a two-letter region name, because a object is not completely language-independent. Several properties, including , , and , depend on culture names. + +The following example illustrates the difference in property values for three objects that represent Belgium. The first is instantiated from a region name (`BE`) only, while the second and third are instantiated from culture names (`fr-BE` for French (Belgium) and `nl-BE` for Dutch (Belgium), respectively). The example uses reflection to retrieve the property values of each object. + +:::code language="csharp" source="~/snippets/csharp/System.Globalization/RegionInfo/propertyvalues1.cs" id="Snippet2"::: + +In scenarios such as the following, use culture names instead of country/region names when you instantiate a object: + +- When the language name is of primary importance. For example, for the `es-US` culture name, you'll probably want your application to display "Estados Unidos" instead of "United States". Using the country/region name (`US`) alone yields "United States" regardless of the language, so you should work with the culture name instead. + +- When script differences must be considered. For example, the country/region `AZ` deals with Azerbaijani cultures that have the names `az-Latn-AZ` and `az-Cyrl-AZ`, and the Latin and Cyrillic scripts can be very different for this country/region. + +- When maintenance of detail is important. The values returned by members can differ depending on whether the object was instantiated by using a culture name or a region name. For example, the following table lists the differences in return values when a object is instantiated by using the "US" region, the "en-US" culture, and the "es-US" culture. + + | Member | "US" | "en-US" | "es-US" | + |-----------------------------------------------------------|-----------------|-----------------|-------------------| + | | `US Dollar` | `US Dollar` | `Dólar de EE.UU.` | + | | `US` | `en-US` | `es-US` | + | | `United States` | `United States` | `Estados Unidos` | + | | `US` | `en-US` | `es-US` | +## Example The following example demonstrates several members of the class. diff --git a/xml/System.Globalization/SortKey.xml b/xml/System.Globalization/SortKey.xml index 4f36eeb565f..42a63ce82d6 100644 --- a/xml/System.Globalization/SortKey.xml +++ b/xml/System.Globalization/SortKey.xml @@ -55,7 +55,48 @@ Represents the result of mapping a string to its sort key. - For more information about this API, see Supplemental API remarks for SortKey. + + method returns an instance of the class that reflects the culture-sensitive mapping of characters in a specified string. The value of a object is its key data, which is returned by the property. This key data consists of a series of bytes that encode the string, culture-specific sorting rules, and user-specified comparison options. A comparison using sort keys consists of a bitwise comparison of the corresponding key data in each sort key. For example, if you create a sort key by calling the method with a value of , a string comparison operation that uses the sort key is case-insensitive. + +After you create a sort key for a string, you compare sort keys by calling the static method. This method performs a simple byte-by-byte comparison, so it is much faster than the or method. + +> [!NOTE] +> You can download the [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921), a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, the [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt), the sort weight table for Linux and macOS. + +## Performance considerations + +When performing a string comparison, the and methods yield the same results, but they target different scenarios. + +At a high level, the method generates the sort key for each string, performs the comparison, and then discards the sort key and returns the result of the comparison. However, the method actually doesn't generate an entire sort key to perform the comparison. Instead, the method generates the key data for each text element (that is, base character, surrogate pair, or combining character sequence) in each string. The method then compares the key data for the corresponding text elements. The operation terminates as soon as the ultimate result of the comparison is determined. Sort key information is computed, but no object is created. This strategy is economical in terms of performance if both strings are compared once, but becomes expensive if the same strings are compared many times. + +The method requires generation of a object for each string before performing the comparison. This strategy is expensive in terms of performance for the first comparison because of the time and memory invested to generate the objects. However, it becomes economical if the same sort keys are compared many times. + +For example, suppose you write an application that searches a database table for the row in which the string-based index column matches a specified search string. The table contains thousands of rows, and comparing the search string to the index in each row will take a long time. Therefore, when the application stores a row and its index column, it also generates and stores the sort key for the index in a column dedicated to improving search performance. When the application searches for a target row, it compares the sort key for the search string to the sort key for the index string, instead of comparing the search string to the index string. + +## Security considerations + +The method returns a object with the value based on a specified string and value, and the culture associated with the underlying object. If a security decision depends on a string comparison or case change, you should use the method of the invariant culture to ensure that the behavior of the operation is consistent, regardless of the culture settings of the operating system. + +Use the following steps to obtain a sort key: + +1. Retrieve the invariant culture from the property. + +2. Retrieve a object for the invariant culture from the property. + +3. Call the method. + +Working with the value of a object is equivalent to calling the Windows `LCMapString` method with the LCMAP_SORTKEY value specified. However, for the object, the sort keys for English characters precede the sort keys for Korean characters. + + objects can be serialized, but only so that they can cross objects. If an application serializes a object, the application must regenerate all the sort keys when there is a new version of .NET. + +For more information about sort keys, see Unicode Technical Standard #10, "Unicode Collation Algorithm" on the [Unicode Consortium website](https://go.microsoft.com/fwlink/?linkid=37123). + + ]]> + class provides information about the Unicode version used by .NET for string comparison and ordering. It enables developers to write applications that can detect and successfully handle changes in the version of Unicode that is used to compare and sort an application's strings. + +You can instantiate a object in two ways: + +- By calling the constructor, which instantiates a new object based on a version number and sort ID. This constructor is most useful when recreating a object from saved data. +- By retrieving the value of the property. This property provides information about the Unicode version used by the .NET implementation on which the application is running. + +The class has two properties, and , that indicate the Unicode version and the specific culture used for string comparison. The property is an arbitrary numeric value that reflects the Unicode version used for string comparison, and the property is an arbitrary that reflects the culture whose conventions are used for string comparison. The values of these two properties are important only when you compare two objects by using the method, the operator, or the operator. + +You typically use a object when saving or retrieving some form of culture-sensitive, ordered string data, such as indexes or the literal strings themselves. This requires the following steps: + +1. When the ordered string data is saved, the and property values are also saved. + +2. When the ordered string data is retrieved, you can recreate the object used for ordering the strings by calling the constructor. + +3. This newly instantiated object is compared with a object that reflects the culture whose conventions are used to order the string data. + +4. If the two objects are not equal, the string data must be reordered. +## Example The following example contains a portion of the source code from an application that uses the class to ensure that the native names of objects are ordered appropriately for the current system and current culture. It uses the and objects to store and retrieve ordered data from a data file named `Regions.dat` rather than retrieving and ordering data each time the application is run. The example first checks to determine whether the data file exists. If it does not, it creates the data and sets the `reindex` flag, which indicates that the data must be resorted and saved again. Otherwise, it retrieves the data and compares the saved object with the object for the current culture on the current system. If they aren't equal, or if the `reindex` flag had been set previously, it resorts to the data. diff --git a/xml/System.IO/FileStream.xml b/xml/System.IO/FileStream.xml index 9f5e16a5f8e..6bab2e9fee6 100644 --- a/xml/System.IO/FileStream.xml +++ b/xml/System.IO/FileStream.xml @@ -66,7 +66,39 @@ Provides a for a file, supporting both synchronous and asynchronous read and write operations. - For more information about this API, see Supplemental API remarks for FileStream. + + class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output. You can use the , , , and methods to perform synchronous operations, or the , , , and methods to perform asynchronous operations. Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a Windows 8.x Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. buffers input and output for better performance. + +> [!IMPORTANT] +> This type implements the interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the interface topic. + +The property detects whether the file handle was opened asynchronously. You specify this value when you create an instance of the class using a constructor that has an `isAsync`, `useAsync`, or `options` parameter. When the property is `true`, the stream utilizes overlapped I/O to perform file operations asynchronously. However, the property does not have to be `true` to call the , , or method. When the property is `false` and you call the asynchronous read and write operations, the UI thread is still not blocked, but the actual I/O operation is performed synchronously. + +The method supports random access to files. allows the read/write position to be moved to any position within the file. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three members of the enumeration. + +> [!NOTE] +> Disk files always support random access. At the time of construction, the property value is set to `true` or `false` depending on the underlying file type. If the underlying file type is FILE_TYPE_DISK, as defined in winbase.h, the property value is `true`. Otherwise, the property value is `false`. + +If a process terminates with part of a file locked or closes a file that has outstanding locks, the behavior is undefined. + +For directory operations and other file operations, see the , , and classes. The class is a utility class that has static methods primarily for the creation of objects based on file paths. The class creates a stream from a byte array and is similar to the class. + +For a list of common file and directory operations, see [Common I/O Tasks](/dotnet/standard/io/common-i-o-tasks). + +## Detection of stream position changes + +When a object does not have an exclusive hold on its handle, another thread could access the file handle concurrently and change the position of the operating system's file pointer that is associated with the file handle. In this case, the cached position in the object and the cached data in the buffer could be compromised. The object routinely performs checks on methods that access the cached buffer to ensure that the operating system's handle position is the same as the cached position used by the object. + +If an unexpected change in the handle position is detected in a call to the method, .NET discards the contents of the buffer and reads the stream from the file again. This can affect performance, depending on the size of the file and any other processes that could affect the position of the file stream. + +If an unexpected change in the handle position is detected in a call to the method, the contents of the buffer are discarded and an exception is thrown. + +A object will not have an exclusive hold on its handle when either the property is accessed to expose the handle or the object is given the property in its constructor. + + ]]> + constructors. diff --git a/xml/System.IO/FileSystemWatcher.xml b/xml/System.IO/FileSystemWatcher.xml index bd13122dca1..3b8545d70d4 100644 --- a/xml/System.IO/FileSystemWatcher.xml +++ b/xml/System.IO/FileSystemWatcher.xml @@ -65,7 +65,54 @@ Listens to the file system change notifications and raises events when a directory, or file in a directory, changes. - For more information about this API, see Supplemental API remarks for FileSystemWatcher. + + to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer. + +To watch for changes in all files, set the property to an empty string ("") or use wildcards ("*.\*"). To watch a specific file, set the property to the file name. For example, to watch for changes in the file MyDoc.txt, set the property to "MyDoc.txt". You can also watch for changes in a certain type of file. For example, to watch for changes in text files, set the property to "\*.txt". + +There are several types of changes you can watch for in a directory or file. For example, you can watch for changes in `Attributes`, the `LastWrite` date and time, or the `Size` of files or directories. This is done by setting the property to one of the values. For more information on the type of changes you can watch, see . + +You can watch for renaming, deletion, or creation of files or directories. For example, to watch for renaming of text files, set the property to "*.txt" and call the method with a specified for its parameter. + +The Windows operating system notifies your component of file changes in a buffer created by the . If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer with the property is expensive, as it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small yet large enough to not miss any file change events. To avoid a buffer overflow, use the and properties so you can filter out unwanted change notifications. + +For a list of initial property values for an instance of , see the constructor. + +Considerations when using the class: + +- Hidden files are not ignored. +- In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFil~.Lon". +- This class contains a link demand and an inheritance demand at the class level that applies to all members. A is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see [Link Demands](/dotnet/framework/misc/link-demands). +- The maximum size you can set for the property for monitoring a directory over the network is 64 KB. + +## Copy and move folders + +The operating system and object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. If you cut and paste a folder with files into a folder being watched, the object reports only the folder as new, but not its contents because they are essentially only renamed. + +To be notified that the contents of folders have been moved or copied into a watched folder, provide and event handler methods as suggested in the following table. + +|Event Handler|Events Handled|Performs| +|-------------------|--------------------|--------------| +||, , |Report changes in file attributes, created files, and deleted files.| +|||List the old and new paths of renamed files and folders, expanding recursively if needed.| + +## Events and buffer sizes + +Note that several factors can affect which file system change events are raised, as described by the following: + +- Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several and some and events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by . +- The can watch disks as long as they are not switched or removed. The does not raise events for CDs and DVDs, because time stamps and properties cannot change. Remote computers must have one of the required platforms installed for the component to function properly. + +Note that a may miss an event when the buffer size is exceeded. To avoid missing events, follow these guidelines: + +- Increase the buffer size by setting the property. +- Avoid watching files with long file names, because a long file name contributes to filling up the buffer. Consider renaming these files using shorter names. +- Keep your event handling code as short as possible. + + ]]> + to watch the directory specified at run time. The component is set to watch for changes in `LastWrite` and `LastAccess` time, the creation, deletion, or renaming of text files in the directory. If a file is changed, created, or deleted, the path to the file prints to the console. When a file is renamed, the old and new paths print to the console. From b69152f7c4ed9878178afbc674f6b49a7223a90d Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:02:12 -0700 Subject: [PATCH 2/8] respond to feedback --- .../CultureInfo/CurrentCulture/Async1.cs | 4 +-- .../CultureInfo/CurrentCulture/Get1.cs | 3 +- .../CultureInfo/CurrentCulture/Program.cs | 1 + .../CultureInfo/CurrentCulture/aspculture1.cs | 20 ----------- .../CurrentCulture/aspculture13.cs | 20 ----------- .../CurrentCulture/changeculture11.cs | 18 ++++------ .../CurrentCulture/currentculture.cs | 2 +- .../CurrentCulture/currentculture.csproj | 3 +- .../CultureInfo/CurrentCulture/specific1.cs | 1 + .../CultureInfo/CurrentCulture/specific12.cs | 3 +- .../CultureInfo/CurrentUICulture/Async1.cs | 1 + .../DateTimeFormatInfo/example5.cs | 4 +-- .../DateTimeFormatInfo/formatprovider1.cs | 7 ++-- .../CurrentCulture/aspculture13.vb | 23 ------------ .../CurrentCulture/changeculture11.vb | 35 ------------------- .../CultureInfo/CurrentUICulture/Async1.vb | 7 ++-- .../CultureInfo/CurrentUICulture/Get1.vb | 3 +- xml/System.Globalization/CultureInfo.xml | 8 +---- xml/System.Globalization/PersianCalendar.xml | 12 ++----- xml/System.Globalization/SortVersion.xml | 19 +--------- xml/System.IO/FileStream.xml | 2 +- 21 files changed, 35 insertions(+), 161 deletions(-) create mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Program.cs delete mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture1.cs delete mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs delete mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb delete mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs index 862b15bbfd7..171fa9ffa0d 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs @@ -1,8 +1,7 @@ -// +// using System; using System.Collections.Generic; using System.Globalization; -using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -26,6 +25,7 @@ public static async Task Main() await Task.WhenAll(tasks.ToArray()); } } + // The example displays output like the following: // The current culture is en-US // Current culture changed to pt-BR diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs index f07ebd7151e..35e83e8af8f 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Get1.cs @@ -1,4 +1,4 @@ -// +// using System; using System.Globalization; @@ -10,6 +10,7 @@ public static void Main() Console.WriteLine($"The current culture is {culture.NativeName} [{culture.Name}]"); } } + // The example displays output like the following: // The current culture is English (United States) [en-US] // diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Program.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Program.cs new file mode 100644 index 00000000000..c4689afebd9 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Program.cs @@ -0,0 +1 @@ +SetCultureExample.Run(); diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture1.cs deleted file mode 100644 index 5f032d78678..00000000000 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Globalization; -using System.Threading; - -public class Example -{ - public static void Main() - { - // - Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]); - // - } -} - -public class Request -{ - private static string[] langs = new string[3]; - - public static string[] UserLanguages { get { return langs; } } -} \ No newline at end of file diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs deleted file mode 100644 index f35caeb4dc8..00000000000 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Globalization; -using System.Threading; - -public class Example13 -{ - public static void Main() - { - // - CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(Request13.UserLanguages[0]); - // - } -} - -public class Request13 -{ - private static string[] langs = new string[3]; - - public static string[] UserLanguages { get { return langs; } } -} diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs index 699931f4242..4e830af40bf 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs @@ -1,4 +1,4 @@ -// +// using System; using System.Globalization; using System.Threading; @@ -7,27 +7,23 @@ public class Info11 : MarshalByRefObject { public void ShowCurrentCulture() { - Console.WriteLine($"Culture of {Thread.CurrentThread.Name} in application domain {AppDomain.CurrentDomain.FriendlyName}: {CultureInfo.CurrentCulture.Name}"); + Console.WriteLine($"Culture of thread {Thread.CurrentThread.Name}: {CultureInfo.CurrentCulture.Name}"); } } -public class Example11 +public class SetCultureExample { - public static void Main() + public static void Run() { Info11 inf = new Info11(); // Set the current culture to Dutch (Netherlands). Thread.CurrentThread.Name = "MainThread"; CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL"); inf.ShowCurrentCulture(); - - // Create a new application domain. - AppDomain ad = AppDomain.CreateDomain("Domain2"); - Info11 inf2 = (Info11)ad.CreateInstanceAndUnwrap(typeof(Info11).Assembly.FullName, "Info11"); - inf2.ShowCurrentCulture(); } } + // The example displays the following output: -// Culture of MainThread in application domain ChangeCulture1.exe: nl-NL -// Culture of MainThread in application domain Domain2: nl-NL +// +// Culture of thread MainThread: nl-NL // diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.cs index e1913781ccb..1a64b177e17 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.cs @@ -1,7 +1,6 @@ // using System; using System.Globalization; -using System.Threading; public class Example0 { @@ -22,6 +21,7 @@ public static void Main() Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name); } } + // The example displays the following output: // CurrentCulture is en-US. // CurrentCulture is now th-TH. diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.csproj b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.csproj index 422acfc0ed0..a15a29bf12c 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.csproj +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.csproj @@ -2,8 +2,7 @@ Exe - net4.8 - Example5 + net10.0 diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific1.cs index 133f1e0477d..f73023ec154 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific1.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific1.cs @@ -19,6 +19,7 @@ public static void Main() Console.WriteLine("{0:C2}", value); } } + // The example displays the following output: // Current Culture: fr-CA // 1 634,92 $ diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs index 85f7b6e54eb..e7ce10a6004 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs @@ -1,4 +1,4 @@ -// +// using System; using System.Globalization; using System.Threading; @@ -17,6 +17,7 @@ public static void Main() Console.WriteLine($"{value:C2}"); } } + // The example displays the following output: // Current Culture: fr-CA // 1 634,92 $ diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs index 37fc0573971..550215fa865 100644 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs +++ b/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs @@ -26,6 +26,7 @@ public static async Task Main() await Task.WhenAll(tasks.ToArray()); } } + // The example displays output like the following: // The current UI culture is en-US // Current UI culture changed to pt-BR diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs index e23c4454dad..dc3e8f31199 100644 --- a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs @@ -19,7 +19,7 @@ public static void Main() dtfi.LongTimePattern = ReplaceWith24HourClock(dtfi.LongTimePattern); dtfi.ShortTimePattern = ReplaceWith24HourClock(dtfi.ShortTimePattern); - Console.WriteLine("Modififed Property Values:"); + Console.WriteLine("Modified Property Values:"); Console.WriteLine("ShortTimePattern: " + dtfi.ShortTimePattern); Console.WriteLine("LongTimePattern: " + dtfi.LongTimePattern); Console.WriteLine("FullDateTimePattern: " + dtfi.FullDateTimePattern); @@ -40,7 +40,7 @@ private static string ReplaceWith24HourClock(string fmt) // LongTimePattern: h:mm:ss tt // FullDateTimePattern: dddd, MMMM dd, yyyy h:mm:ss tt // -// Modififed Property Values: +// Modified Property Values: // ShortTimePattern: HH:mm // LongTimePattern: HH:mm:ss // FullDateTimePattern: dddd, MMMM dd, yyyy HH:mm:ss diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs index 1cdaa7e5fd9..76786a13394 100644 --- a/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs @@ -4,7 +4,7 @@ public class CurrentCultureFormatProvider : IFormatProvider { - public Object GetFormat(Type formatType) + public Object? GetFormat(Type formatType) { Console.WriteLine($"Requesting an object of type {formatType.Name}"); if (formatType == typeof(NumberFormatInfo)) @@ -20,17 +20,18 @@ public class FormatProviderEx1 { public static void Main() { - DateTime dateValue = new DateTime(2013, 5, 28, 13, 30, 0); + DateTime dateValue = new(2013, 5, 28, 13, 30, 0); string value = dateValue.ToString("F", new CurrentCultureFormatProvider()); Console.WriteLine(value); Console.WriteLine(); - string composite = String.Format(new CurrentCultureFormatProvider(), + string composite = string.Format(new CurrentCultureFormatProvider(), "Date: {0:d} Amount: {1:C} Description: {2}", dateValue, 1264.03m, "Service Charge"); Console.WriteLine(composite); Console.WriteLine(); } } + // The example displays output like the following: // Requesting an object of type DateTimeFormatInfo // Tuesday, May 28, 2013 1:30:00 PM diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb deleted file mode 100644 index 91257a0b53f..00000000000 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb +++ /dev/null @@ -1,23 +0,0 @@ -' Visual Basic .NET Document -Option Strict On - -Imports System.Globalization -Imports System.Threading - -Module Example - Public Sub S1() - ' - Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0)) - ' - End Sub -End Module - - -Public Class Request - Private Shared langs(3) As String - Public Shared ReadOnly Property UserLanguages As String() - Get - Return langs - End Get - End Property -End Class diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb deleted file mode 100644 index 59a55590241..00000000000 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb +++ /dev/null @@ -1,35 +0,0 @@ -' Visual Basic .NET Document -Option Strict On - -' -Imports System.Globalization -Imports System.Threading - -Public Class Info : Inherits MarshalByRefObject - Public Sub ShowCurrentCulture() - Console.WriteLine("Culture of {0} in application domain {1}: {2}", - Thread.CurrentThread.Name, - AppDomain.CurrentDomain.FriendlyName, - CultureInfo.CurrentCulture.Name) - End Sub -End Class - -Module Example2 - Public Sub S1() - Dim inf As New Info() - ' Set the current culture to Dutch (Netherlands). - Thread.CurrentThread.Name = "MainThread" - CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL") - inf.ShowCurrentCulture() - - ' Create a new application domain. - Dim ad As AppDomain = AppDomain.CreateDomain("Domain2") - Dim inf2 As Info = CType(ad.CreateInstanceAndUnwrap(GetType(Info).Assembly.FullName, "Info"), - Info) - inf2.ShowCurrentCulture() - End Sub -End Module -' This example displays the following output: -' Culture of MainThread in application domain Example.exe: nl-NL -' Culture of MainThread in application domain Domain2: nl-NL -' diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb index 1b6cc161e69..639a89bc0e6 100644 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb @@ -13,7 +13,7 @@ Module Example1 Thread.CurrentThread.CurrentUICulture.Name) Thread.CurrentThread.CurrentUICulture = New CultureInfo("pt-BR") ' Change the current UI culture to Portuguese (Brazil). - Console.WriteLine("Current culture changed to {0}", + Console.WriteLine("Current UI culture changed to {0}", Thread.CurrentThread.CurrentUICulture.Name) Console.WriteLine("Application thread is thread {0}", Thread.CurrentThread.ManagedThreadId) @@ -29,9 +29,10 @@ Module Example1 Task.WaitAll(tasks.ToArray()) End Sub End Module + ' The example displays output like the following: -' The current culture is en-US -' Current culture changed to pt-BR +' The current UI culture is en-US +' Current UI culture changed to pt-BR ' Application thread is thread 9 ' Culture of task 2 on thread 11 is pt-BR ' Culture of task 1 on thread 10 is pt-BR diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb index 96b9294dac3..c9b65f3b48a 100644 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Get1.vb @@ -6,11 +6,12 @@ Imports System.Globalization Module Example3 Public Sub Main() - Dim culture As CultureInfo = CultureInfo.CurrentCulture + Dim culture As CultureInfo = CultureInfo.CurrentUICulture Console.WriteLine("The current UI culture is {0} [{1}]", culture.NativeName, culture.Name) End Sub End Module + ' The example displays output like the following: ' The current UI culture is English (United States) [en-US] ' diff --git a/xml/System.Globalization/CultureInfo.xml b/xml/System.Globalization/CultureInfo.xml index 313aa18fefd..7e2f41c4686 100644 --- a/xml/System.Globalization/CultureInfo.xml +++ b/xml/System.Globalization/CultureInfo.xml @@ -1167,10 +1167,9 @@ The property to the new culture. If you explicitly change a thread's culture in this way, that change persists if the thread crosses application domain boundaries. The following example changes the current thread culture to Dutch (Netherlands). It also shows that, when the current thread crosses application domain boundaries, its current culture remains changed. +To change the culture that's used by an existing thread, you set the property to the new culture. The following example changes the current thread culture to Dutch (Netherlands). :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/changeculture11.cs" id="Snippet11"::: -:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/changeculture11.vb" id="Snippet11"::: > [!NOTE] > Changing the culture by using the property requires a permission with the value set. Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code. @@ -1180,11 +1179,6 @@ Starting with .NET Framework 4, you can explicitly change the current thread cul :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs" id="Snippet12"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb" id="Snippet12"::: -You can also use the property along with the property to set the property of an ASP.NET application to the user's preferred culture, as the following example illustrates. - -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture13.cs" id="Snippet13"::: -:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/aspculture13.vb" id="Snippet13"::: - ## The current culture and user overrides Windows allows users to override the standard property values of the object and its associated objects by using **Regional and Language Options** in Control Panel. The object returned by the property reflects these user overrides in the following cases: diff --git a/xml/System.Globalization/PersianCalendar.xml b/xml/System.Globalization/PersianCalendar.xml index 56cdef675fb..f6bda4b88c3 100644 --- a/xml/System.Globalization/PersianCalendar.xml +++ b/xml/System.Globalization/PersianCalendar.xml @@ -79,17 +79,9 @@ The Persian calendar is based on a solar year and is approximately 365 days long Each of the first six months in the Persian calendar has 31 days, each of the next five months has 30 days, and the last month has 29 days in a common year and 30 days in a leap year. A leap year is a year that, when divided by 33, has a remainder of 1, 5, 9, 13, 17, 22, 26, or 30. For example, the year 1370 is a leap year because dividing it by 33 yields a remainder of 17. There are approximately eight leap years in every 33-year cycle. -## The PersianCalendar class and .NET versions +## Hijri solar astronomical algorithm -Starting with .NET Framework 4.6, the class uses the Hijri solar astronomical algorithm rather than an observational algorithm to calculate dates. This makes the implementation consistent with the Persian calendar in use in Iran and Afghanistan, the two countries in which the Persian calendar is in most widespread use. The change affects all apps running on .NET Framework 4 or later if .NET Framework 4.6 is installed. - -As a result of the changed algorithm: - -- The two algorithms should return identical results when converting dates between 1800 and 2123 in the Gregorian calendar. -- The two algorithms might return different results when converting dates before 1800 and after 2123 in the Gregorian calendar. -- The property value has changed from March 21, 0622 in the Gregorian calendar to March 22, 0622 in the Gregorian calendar. -- The property value has changed from the 10th day of the 10th month of the year 9378 in the Persian calendar to the 13th day of the 10th month of the year 9378 in the Persian calendar. -- The method might return a different result than it did previously. +The class uses the Hijri solar astronomical algorithm rather than an observational algorithm to calculate dates. This makes the implementation consistent with the Persian calendar in use in Iran and Afghanistan, the two countries in which the Persian calendar is in most widespread use. ## Use the PersianCalendar class diff --git a/xml/System.Globalization/SortVersion.xml b/xml/System.Globalization/SortVersion.xml index 8e94603e762..47464f0220b 100644 --- a/xml/System.Globalization/SortVersion.xml +++ b/xml/System.Globalization/SortVersion.xml @@ -58,24 +58,7 @@ ## Remarks - ## Sorting and string comparison in .NET Framework - -Through .NET Framework 4, each version of .NET Framework included tables that contained sort weights and data on string normalization and that are based on a particular version of Unicode. In .NET Framework 4.5 and later versions, the presence of these tables depends on the operating system: - -- On Windows 7 and previous versions, the tables continue to be used for comparing and ordering strings. -- On Windows 8, .NET Framework delegates string comparison and ordering operations to the operating system. - -Consequently, the result of a string comparison can depend not only on .NET Framework version, but also on the operating system version, as the following table shows. Note that this list of supported Unicode versions applies to character comparison and sorting only; it does not apply to classification of Unicode characters by category. - -| .NET Framework version | Operating system | Unicode version | -|------------------------|------------------------------|-----------------| -| 4 | All operating systems | Unicode 5.0 | -| 4.5 and later versions | Windows 7 | Unicode 5.0 | -| 4.5 and later versions | Windows 8 and later versions | Unicode 6.0 | - -On Windows 8, because the version of Unicode used in string comparison and ordering depends on the version of the operating system, the results of string comparison may differ even for applications that run on a specific version of .NET Framework. - -## Sorting and string comparison in .NET Core +## Sorting and string comparison All versions of .NET (Core) rely on the underlying operating system when performing string comparisons. Therefore, the results of a string comparison or the order in which strings are sorted depends on the version of Unicode used by the operating system when performing the comparison. On Linux, macOS, and Windows 10 and later versions, [International Components for Unicode](https://icu.unicode.org/) libraries provide the implementation for comparison and sorting APIs. diff --git a/xml/System.IO/FileStream.xml b/xml/System.IO/FileStream.xml index 6bab2e9fee6..9356c20f73d 100644 --- a/xml/System.IO/FileStream.xml +++ b/xml/System.IO/FileStream.xml @@ -69,7 +69,7 @@ class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output. You can use the , , , and methods to perform synchronous operations, or the , , , and methods to perform asynchronous operations. Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a Windows 8.x Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. buffers input and output for better performance. +Use the class to read from, write to, open, and close files on a file system, and to manipulate other file-related operating system handles, including pipes, standard input, and standard output. You can use the , , , and methods to perform synchronous operations, or the , , , and methods to perform asynchronous operations. Use the asynchronous methods to perform resource-intensive file operations without blocking the main thread. This performance consideration is particularly important in a desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. buffers input and output for better performance. > [!IMPORTANT] > This type implements the interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its method in a `try`/`catch` block. To dispose of it indirectly, use a language construct such as `using` (in C#) or `Using` (in Visual Basic). For more information, see the "Using an Object that Implements IDisposable" section in the interface topic. From f6e6e23f37da96a5a268a020194d65a181e79272 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:47:51 -0700 Subject: [PATCH 3/8] fix build errors --- .../CultureInfo/Overview/appdomainex1.cs | 77 +++++++++++++++++ .../CultureInfo/Overview/asyncculture1.cs | 66 ++++++++++++++ .../CultureInfo/Overview/asyncculture3.cs | 67 +++++++++++++++ .../CultureInfo/Overview/changeui1.cs | 24 ++++++ .../CultureInfo/Overview/current1.cs | 19 ++++ .../CultureInfo/Overview/currentui1.cs | 19 ++++ .../CultureInfo/Overview/defaultthread1.cs | 67 +++++++++++++++ .../CultureInfo/Overview/getcultures1.cs | 44 ++++++++++ .../CultureInfo/Overview/setthreads1.cs | 67 +++++++++++++++ .../Overview/customize_currency1.cs | 42 +++++++++ .../Overview/customize_ssn1.cs | 37 ++++++++ .../Overview/formatprovider1.cs | 42 +++++++++ .../NumberFormatInfo/Overview/instantiate1.cs | 23 +++++ .../NumberFormatInfo/Overview/instantiate2.cs | 21 +++++ .../NumberFormatInfo/Overview/instantiate3.cs | 32 +++++++ .../NumberFormatInfo/Overview/instantiate4.cs | 25 ++++++ .../NumberFormatInfo/Overview/instantiate5.cs | 33 +++++++ .../NumberFormatInfo/Overview/instantiate6.cs | 86 +++++++++++++++++++ .../NumberFormatInfo/Overview/parse1.cs | 40 +++++++++ .../Overview/parsepersisted.cs | 80 +++++++++++++++++ .../NumberFormatInfo/Overview/parseuser1.cs | 43 ++++++++++ .../NumberFormatInfo/Overview/project.csproj | 9 ++ .../NumberFormatInfo/Overview/properties1.cs | 41 +++++++++ .../NumberFormatInfo/Overview/properties2.cs | 22 +++++ xml/System.Globalization/CompareOptions.xml | 3 +- xml/System.Globalization/CultureInfo.xml | 27 +++--- xml/System.Globalization/NumberFormatInfo.xml | 28 +++--- xml/System.Globalization/RegionInfo.xml | 2 +- 28 files changed, 1053 insertions(+), 33 deletions(-) create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/appdomainex1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture3.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/changeui1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/current1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/currentui1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/defaultthread1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/getcultures1.cs create mode 100644 snippets/csharp/System.Globalization/CultureInfo/Overview/setthreads1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_currency1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_ssn1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/formatprovider1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate2.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate3.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate4.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate5.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate6.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parse1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parsepersisted.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parseuser1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/project.csproj create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties1.cs create mode 100644 snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties2.cs diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/appdomainex1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/appdomainex1.cs new file mode 100644 index 00000000000..2fac9bc1928 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/appdomainex1.cs @@ -0,0 +1,77 @@ +// +using System; +using System.Globalization; + +public class Example +{ + public static void Main() + { + // Set the default culture and display the current date in the current application domain. + Info info1 = new Info(); + SetAppDomainCultures("fr-FR"); + + // Create a second application domain. + AppDomainSetup setup = new AppDomainSetup(); + setup.AppDomainInitializer = SetAppDomainCultures; + setup.AppDomainInitializerArguments = new string[] { "ru-RU" }; + AppDomain domain = AppDomain.CreateDomain("Domain2", null, setup); + // Create an Info object in the new application domain. + Info info2 = (Info)domain.CreateInstanceAndUnwrap(typeof(Example).Assembly.FullName, + "Info"); + + // Execute methods in the two application domains. + info2.DisplayDate(); + info2.DisplayCultures(); + + info1.DisplayDate(); + info1.DisplayCultures(); + } + + public static void SetAppDomainCultures(string[] names) + { + SetAppDomainCultures(names[0]); + } + + public static void SetAppDomainCultures(string name) + { + try + { + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(name); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(name); + } + // If an exception occurs, we'll just fall back to the system default. + catch (CultureNotFoundException) + { + return; + } + catch (ArgumentException) + { + return; + } + } +} + +public class Info : MarshalByRefObject +{ + public void DisplayDate() + { + Console.WriteLine($"Today is {DateTime.Now:D}"); + } + + public void DisplayCultures() + { + Console.WriteLine($"Application domain is {AppDomain.CurrentDomain.Id}"); + Console.WriteLine($"Default Culture: {CultureInfo.DefaultThreadCurrentCulture}"); + Console.WriteLine($"Default UI Culture: {CultureInfo.DefaultThreadCurrentUICulture}"); + } +} +// The example displays the following output: +// Today is 14 октября 2011 г. +// Application domain is 2 +// Default Culture: ru-RU +// Default UI Culture: ru-RU +// Today is vendredi 14 octobre 2011 +// Application domain is 1 +// Default Culture: fr-FR +// Default UI Culture: fr-FR +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture1.cs new file mode 100644 index 00000000000..f92562bd469 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture1.cs @@ -0,0 +1,66 @@ +// +using System; +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; + +public class AsyncCultureEx1 +{ + public static void Main() + { + decimal[] values = { 163025412.32m, 18905365.59m }; + string formatString = "C2"; + + string FormatDelegate() + { + string output = $"Formatting using the {CultureInfo.CurrentCulture.Name} " + + $"culture on thread {Thread.CurrentThread.ManagedThreadId}.\n"; + foreach (decimal value in values) + output += $"{value.ToString(formatString)} "; + + output += Environment.NewLine; + return output; + } + + Console.WriteLine($"The example is running on thread {Thread.CurrentThread.ManagedThreadId}"); + // Make the current culture different from the system culture. + Console.WriteLine($"The current culture is {CultureInfo.CurrentCulture.Name}"); + if (CultureInfo.CurrentCulture.Name == "fr-FR") + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + else + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); + + Console.WriteLine($"Changed the current culture to {CultureInfo.CurrentCulture.Name}.\n"); + + // Execute the delegate synchronously. + Console.WriteLine("Executing the delegate synchronously:"); + Console.WriteLine(FormatDelegate()); + + // Call an async delegate to format the values using one format string. + Console.WriteLine("Executing a task asynchronously:"); + var t1 = Task.Run(FormatDelegate); + Console.WriteLine(t1.Result); + + Console.WriteLine("Executing a task synchronously:"); + var t2 = new Task(FormatDelegate); + t2.RunSynchronously(); + Console.WriteLine(t2.Result); + } +} +// The example displays the following output: +// The example is running on thread 1 +// The current culture is en-US +// Changed the current culture to fr-FR. +// +// Executing the delegate synchronously: +// Formatting using the fr-FR culture on thread 1. +// 163 025 412,32 € 18 905 365,59 € +// +// Executing a task asynchronously: +// Formatting using the fr-FR culture on thread 3. +// 163 025 412,32 € 18 905 365,59 € +// +// Executing a task synchronously: +// Formatting using the fr-FR culture on thread 1. +// 163 025 412,32 € 18 905 365,59 € +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture3.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture3.cs new file mode 100644 index 00000000000..2e54eb2466b --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture3.cs @@ -0,0 +1,67 @@ +// +using System; +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; + +public class AsyncCultureEx3 +{ + public static void Main() + { + decimal[] values = { 163025412.32m, 18905365.59m }; + string formatString = "C2"; + Func formatDelegate = () => + { + string output = String.Format("Formatting using the {0} culture on thread {1}.\n", + CultureInfo.CurrentCulture.Name, + Thread.CurrentThread.ManagedThreadId); + foreach (var value in values) + output += String.Format("{0} ", value.ToString(formatString)); + + output += Environment.NewLine; + return output; + }; + + Console.WriteLine($"The example is running on thread {Thread.CurrentThread.ManagedThreadId}"); + // Make the current culture different from the system culture. + Console.WriteLine($"The current culture is {CultureInfo.CurrentCulture.Name}"); + if (CultureInfo.CurrentCulture.Name == "fr-FR") + Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); + else + Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); + + Console.WriteLine($"Changed the current culture to {CultureInfo.CurrentCulture.Name}.\n"); + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture; + + // Execute the delegate synchronously. + Console.WriteLine("Executing the delegate synchronously:"); + Console.WriteLine(formatDelegate()); + + // Call an async delegate to format the values using one format string. + Console.WriteLine("Executing a task asynchronously:"); + var t1 = Task.Run(formatDelegate); + Console.WriteLine(t1.Result); + + Console.WriteLine("Executing a task synchronously:"); + var t2 = new Task(formatDelegate); + t2.RunSynchronously(); + Console.WriteLine(t2.Result); + } +} +// The example displays the following output: +// The example is running on thread 1 +// The current culture is en-US +// Changed the current culture to fr-FR. +// +// Executing the delegate synchronously: +// Formatting using the fr-FR culture on thread 1. +// 163 025 412,32 € 18 905 365,59 € +// +// Executing a task asynchronously: +// Formatting using the fr-FR culture on thread 3. +// 163 025 412,32 € 18 905 365,59 € +// +// Executing a task synchronously: +// Formatting using the fr-FR culture on thread 1. +// 163 025 412,32 € 18 905 365,59 € +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/changeui1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/changeui1.cs new file mode 100644 index 00000000000..6c2a2aa7c23 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/changeui1.cs @@ -0,0 +1,24 @@ +// +using System; +using System.Globalization; + +public class ChangeUICultureEx +{ + public static void Main() + { + CultureInfo current = CultureInfo.CurrentUICulture; + Console.WriteLine($"The current UI culture is {current.Name}"); + CultureInfo newUICulture; + if (current.Name.Equals("sl-SI")) + newUICulture = new CultureInfo("hr-HR"); + else + newUICulture = new CultureInfo("sl-SI"); + + CultureInfo.CurrentUICulture = newUICulture; + Console.WriteLine($"The current UI culture is now {CultureInfo.CurrentUICulture.Name}"); + } +} +// The example displays output like the following: +// The current UI culture is en-US +// The current UI culture is now sl-SI +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/current1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/current1.cs new file mode 100644 index 00000000000..a29a8415097 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/current1.cs @@ -0,0 +1,19 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class CurrentCultureEx +{ + public static void Main() + { + CultureInfo culture1 = CultureInfo.CurrentCulture; + CultureInfo culture2 = Thread.CurrentThread.CurrentCulture; + Console.WriteLine($"The current culture is {culture1.Name}"); + Console.WriteLine($"The two CultureInfo objects are equal: {culture1 == culture2}"); + } +} +// The example displays output like the following: +// The current culture is en-US +// The two CultureInfo objects are equal: True +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/currentui1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/currentui1.cs new file mode 100644 index 00000000000..aabecca7d5d --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/currentui1.cs @@ -0,0 +1,19 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class CurrentUIEx +{ + public static void Main() + { + CultureInfo uiCulture1 = CultureInfo.CurrentUICulture; + CultureInfo uiCulture2 = Thread.CurrentThread.CurrentUICulture; + Console.WriteLine($"The current UI culture is {uiCulture1.Name}"); + Console.WriteLine($"The two CultureInfo objects are equal: {uiCulture1 == uiCulture2}"); + } +} +// The example displays output like the following: +// The current UI culture is en-US +// The two CultureInfo objects are equal: True +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/defaultthread1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/defaultthread1.cs new file mode 100644 index 00000000000..ab7f9e4ae13 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/defaultthread1.cs @@ -0,0 +1,67 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class DefaultThreadEx +{ + static Random rnd = new Random(); + + public static void Main() + { + if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") + { + // If current culture is not fr-FR, set culture to fr-FR. + Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); + Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); + } + else + { + // Set culture to en-US. + Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); + Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); + } + ThreadProc(); + + Thread worker = new Thread(ThreadProc); + worker.Name = "WorkerThread"; + worker.Start(); + } + + private static void DisplayThreadInfo() + { + Console.WriteLine($"\nCurrent Thread Name: '{Thread.CurrentThread.Name}'"); + Console.WriteLine($"Current Thread Culture/UI Culture: {Thread.CurrentThread.CurrentCulture.Name}/{Thread.CurrentThread.CurrentUICulture.Name}"); + } + + private static void DisplayValues() + { + // Create new thread and display three random numbers. + Console.WriteLine("Some currency values:"); + for (int ctr = 0; ctr <= 3; ctr++) + Console.WriteLine($" {rnd.NextDouble() * 10:C2}"); + } + + private static void ThreadProc() + { + DisplayThreadInfo(); + DisplayValues(); + } +} +// The example displays output similar to the following: +// Current Thread Name: '' +// Current Thread Culture/UI Culture: fr-FR/fr-FR +// Some currency values: +// 8,11 € +// 1,48 € +// 8,99 € +// 9,04 € +// +// Current Thread Name: 'WorkerThread' +// Current Thread Culture/UI Culture: en-US/en-US +// Some currency values: +// $6.72 +// $6.35 +// $2.90 +// $7.72 +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/getcultures1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/getcultures1.cs new file mode 100644 index 00000000000..ffcdfa70ff2 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/getcultures1.cs @@ -0,0 +1,44 @@ +// +using System; +using System.Globalization; + +public class GetCulturesEx +{ + public static void Main() + { + // Get all custom cultures. + CultureInfo[] custom = CultureInfo.GetCultures(CultureTypes.UserCustomCulture); + if (custom.Length == 0) + { + Console.WriteLine("There are no user-defined custom cultures."); + } + else + { + Console.WriteLine("Custom cultures:"); + foreach (var culture in custom) + Console.WriteLine($" {culture.Name} -- {culture.DisplayName}"); + } + Console.WriteLine(); + + // Get all replacement cultures. + CultureInfo[] replacements = CultureInfo.GetCultures(CultureTypes.ReplacementCultures); + if (replacements.Length == 0) + { + Console.WriteLine("There are no replacement cultures."); + } + else + { + Console.WriteLine("Replacement cultures:"); + foreach (var culture in replacements) + Console.WriteLine($" {culture.Name} -- {culture.DisplayName}"); + } + Console.WriteLine(); + } +} +// The example displays output like the following: +// Custom cultures: +// x-en-US-sample -- English (United States) +// fj-FJ -- Boumaa Fijian (Viti) +// +// There are no replacement cultures. +// diff --git a/snippets/csharp/System.Globalization/CultureInfo/Overview/setthreads1.cs b/snippets/csharp/System.Globalization/CultureInfo/Overview/setthreads1.cs new file mode 100644 index 00000000000..f848f7d9140 --- /dev/null +++ b/snippets/csharp/System.Globalization/CultureInfo/Overview/setthreads1.cs @@ -0,0 +1,67 @@ +// +using System; +using System.Globalization; +using System.Threading; + +public class SetThreadsEx +{ + static Random rnd = new Random(); + + public static void Main() + { + if (Thread.CurrentThread.CurrentCulture.Name != "fr-FR") + { + // If current culture is not fr-FR, set culture to fr-FR. + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR"); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR"); + } + else + { + // Set culture to en-US. + CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); + CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture("en-US"); + } + ThreadProc(); + + Thread worker = new Thread(SetThreadsEx.ThreadProc); + worker.Name = "WorkerThread"; + worker.Start(); + } + + private static void DisplayThreadInfo() + { + Console.WriteLine($"\nCurrent Thread Name: '{Thread.CurrentThread.Name}'"); + Console.WriteLine($"Current Thread Culture/UI Culture: {Thread.CurrentThread.CurrentCulture.Name}/{Thread.CurrentThread.CurrentUICulture.Name}"); + } + + private static void DisplayValues() + { + // Create new thread and display three random numbers. + Console.WriteLine("Some currency values:"); + for (int ctr = 0; ctr <= 3; ctr++) + Console.WriteLine($" {rnd.NextDouble() * 10:C2}"); + } + + private static void ThreadProc() + { + DisplayThreadInfo(); + DisplayValues(); + } +} +// The example displays output similar to the following: +// Current Thread Name: '' +// Current Thread Culture/UI Culture: fr-FR/fr-FR +// Some currency values: +// 6,83 € +// 3,47 € +// 6,07 € +// 1,70 € +// +// Current Thread Name: 'WorkerThread' +// Current Thread Culture/UI Culture: fr-FR/fr-FR +// Some currency values: +// 9,54 € +// 9,50 € +// 0,58 € +// 6,91 € +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_currency1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_currency1.cs new file mode 100644 index 00000000000..1e5cb5579d2 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_currency1.cs @@ -0,0 +1,42 @@ +// +using System; +using System.Globalization; + +public class Example +{ + public static void Main() + { + // Retrieve a writable NumberFormatInfo object. + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + NumberFormatInfo nfi = enUS.NumberFormat; + + // Use the ISO currency symbol instead of the native currency symbol. + nfi.CurrencySymbol = (new RegionInfo(enUS.Name)).ISOCurrencySymbol; + // Change the positive currency pattern to . + nfi.CurrencyPositivePattern = 2; + // Change the negative currency pattern to . + nfi.CurrencyNegativePattern = 12; + + // Produce the result strings by calling ToString. + Decimal[] values = { 1065.23m, 19.89m, -.03m, -175902.32m }; + foreach (var value in values) + Console.WriteLine(value.ToString("C", enUS)); + + Console.WriteLine(); + + // Produce the result strings by calling a composite formatting method. + foreach (var value in values) + Console.WriteLine(String.Format(enUS, "{0:C}", value)); + } +} +// The example displays the following output: +// USD 1,065.23 +// USD 19.89 +// USD -0.03 +// USD -175,902.32 +// +// USD 1,065.23 +// USD 19.89 +// USD -0.03 +// USD -175,902.32 +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_ssn1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_ssn1.cs new file mode 100644 index 00000000000..1e91cac484a --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_ssn1.cs @@ -0,0 +1,37 @@ +// +using System; +using System.Globalization; + +public class CustomizeSSNEx +{ + public static void Main() + { + // Instantiate a read-only NumberFormatInfo object. + CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US"); + NumberFormatInfo nfi = enUS.NumberFormat; + + // Modify the relevant properties. + nfi.NumberGroupSeparator = "-"; + nfi.NumberGroupSizes = new int[] { 3, 2, 4 }; + nfi.NumberDecimalDigits = 0; + + int[] ids = { 111223333, 999776666 }; + + // Produce the result string by calling ToString. + foreach (var id in ids) + Console.WriteLine(id.ToString("N", enUS)); + + Console.WriteLine(); + + // Produce the result string using composite formatting. + foreach (var id in ids) + Console.WriteLine(String.Format(enUS, "{0:N}", id)); + } +} +// The example displays the following output: +// 1112-23-333 +// 9997-76-666 +// +// 1112-23-333 +// 9997-76-666 +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/formatprovider1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/formatprovider1.cs new file mode 100644 index 00000000000..de769d0f2cb --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/formatprovider1.cs @@ -0,0 +1,42 @@ +// +using System; +using System.Globalization; + +public class CurrentCultureFormatProvider : IFormatProvider +{ + public Object GetFormat(Type formatType) + { + Console.WriteLine($"Requesting an object of type {formatType.Name}"); + if (formatType == typeof(NumberFormatInfo)) + return NumberFormatInfo.CurrentInfo; + else if (formatType == typeof(DateTimeFormatInfo)) + return DateTimeFormatInfo.CurrentInfo; + else + return null; + } +} + +public class FormatProviderEx +{ + public static void Main() + { + Decimal amount = 1203.541m; + string value = amount.ToString("C2", new CurrentCultureFormatProvider()); + Console.WriteLine(value); + Console.WriteLine(); + string composite = String.Format(new CurrentCultureFormatProvider(), + "Date: {0} Amount: {1} Description: {2}", + DateTime.Now, 1264.03m, "Service Charge"); + Console.WriteLine(composite); + Console.WriteLine(); + } +} +// The example displays output like the following: +// Requesting an object of type NumberFormatInfo +// $1,203.54 +// +// Requesting an object of type ICustomFormatter +// Requesting an object of type DateTimeFormatInfo +// Requesting an object of type NumberFormatInfo +// Date: 11/15/2012 2:00:01 PM Amount: 1264.03 Description: Service Charge +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate1.cs new file mode 100644 index 00000000000..9f1517d5dad --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate1.cs @@ -0,0 +1,23 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx1 +{ + public static void Main() + { + NumberFormatInfo current1 = CultureInfo.CurrentCulture.NumberFormat; + Console.WriteLine(current1.IsReadOnly); + + NumberFormatInfo current2 = NumberFormatInfo.CurrentInfo; + Console.WriteLine(current2.IsReadOnly); + + NumberFormatInfo current3 = NumberFormatInfo.GetInstance(CultureInfo.CurrentCulture); + Console.WriteLine(current3.IsReadOnly); + } +} +// The example displays the following output: +// True +// True +// True +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate2.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate2.cs new file mode 100644 index 00000000000..940e3956784 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate2.cs @@ -0,0 +1,21 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx2 +{ + public static void Main() + { + NumberFormatInfo current1 = NumberFormatInfo.CurrentInfo; + current1 = (NumberFormatInfo)current1.Clone(); + Console.WriteLine(current1.IsReadOnly); + + CultureInfo culture2 = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name); + NumberFormatInfo current2 = culture2.NumberFormat; + Console.WriteLine(current2.IsReadOnly); + } +} +// The example displays the following output: +// False +// False +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate3.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate3.cs new file mode 100644 index 00000000000..82e9576ce11 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate3.cs @@ -0,0 +1,32 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx3 +{ + public static void Main() + { + CultureInfo culture; + NumberFormatInfo nfi; + + culture = CultureInfo.CurrentCulture; + nfi = culture.NumberFormat; + Console.WriteLine($"Culture Name: {culture.Name}"); + Console.WriteLine($"User Overrides: {culture.UseUserOverride}"); + Console.WriteLine($"Currency Symbol: {culture.NumberFormat.CurrencySymbol}\n"); + + culture = new CultureInfo(CultureInfo.CurrentCulture.Name, false); + Console.WriteLine($"Culture Name: {culture.Name}"); + Console.WriteLine($"User Overrides: {culture.UseUserOverride}"); + Console.WriteLine($"Currency Symbol: {culture.NumberFormat.CurrencySymbol}"); + } +} +// The example displays the following output: +// Culture Name: en-US +// User Overrides: True +// Currency Symbol: USD +// +// Culture Name: en-US +// User Overrides: False +// Currency Symbol: $ +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate4.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate4.cs new file mode 100644 index 00000000000..6156482cc1f --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate4.cs @@ -0,0 +1,25 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx4 +{ + public static void Main() + { + NumberFormatInfo nfi; + + nfi = System.Globalization.NumberFormatInfo.InvariantInfo; + Console.WriteLine(nfi.IsReadOnly); + + nfi = CultureInfo.InvariantCulture.NumberFormat; + Console.WriteLine(nfi.IsReadOnly); + + nfi = new NumberFormatInfo(); + Console.WriteLine(nfi.IsReadOnly); + } +} +// The example displays the following output: +// True +// True +// False +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate5.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate5.cs new file mode 100644 index 00000000000..c43d50b1c1b --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate5.cs @@ -0,0 +1,33 @@ +// +using System; +using System.Globalization; + +public class InstantiateEx5 +{ + public static void Main() + { + CultureInfo culture; + NumberFormatInfo nfi; + + nfi = CultureInfo.GetCultureInfo("id-ID").NumberFormat; + Console.WriteLine($"Read-only: {nfi.IsReadOnly}"); + + culture = new CultureInfo("id-ID"); + nfi = NumberFormatInfo.GetInstance(culture); + Console.WriteLine($"Read-only: {nfi.IsReadOnly}"); + + culture = CultureInfo.CreateSpecificCulture("id-ID"); + nfi = culture.NumberFormat; + Console.WriteLine($"Read-only: {nfi.IsReadOnly}"); + + culture = new CultureInfo("id-ID"); + nfi = culture.NumberFormat; + Console.WriteLine($"Read-only: {nfi.IsReadOnly}"); + } +} +// The example displays the following output: +// Read-only: True +// Read-only: False +// Read-only: False +// Read-only: False +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate6.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate6.cs new file mode 100644 index 00000000000..a115ceb3a73 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate6.cs @@ -0,0 +1,86 @@ +// +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Reflection; + +public class InstantiateEx6 +{ + public static void Main() + { + // Get all the neutral cultures + List names = new List(); + Array.ForEach(CultureInfo.GetCultures(CultureTypes.NeutralCultures), + culture => names.Add(culture.Name)); + names.Sort(); + foreach (var name in names) + { + // Ignore the invariant culture. + if (name == "") continue; + + ListSimilarChildCultures(name); + } + } + + private static void ListSimilarChildCultures(string name) + { + // Create the neutral NumberFormatInfo object. + NumberFormatInfo nfi = CultureInfo.GetCultureInfo(name).NumberFormat; + // Retrieve all specific cultures of the neutral culture. + CultureInfo[] cultures = Array.FindAll(CultureInfo.GetCultures(CultureTypes.SpecificCultures), + culture => culture.Name.StartsWith(name + "-", StringComparison.OrdinalIgnoreCase)); + // Create an array of NumberFormatInfo properties + PropertyInfo[] properties = typeof(NumberFormatInfo).GetProperties(BindingFlags.Instance | BindingFlags.Public); + bool hasOneMatch = false; + + foreach (var ci in cultures) + { + bool match = true; + // Get the NumberFormatInfo for a specific culture. + NumberFormatInfo specificNfi = ci.NumberFormat; + // Compare the property values of the two. + foreach (var prop in properties) + { + // We're not interested in the value of IsReadOnly. + if (prop.Name == "IsReadOnly") continue; + + // For arrays, iterate the individual elements to see if they are the same. + if (prop.PropertyType.IsArray) + { + IList nList = (IList)prop.GetValue(nfi, null); + IList sList = (IList)prop.GetValue(specificNfi, null); + if (nList.Count != sList.Count) + { + match = false; + break; + } + + for (int ctr = 0; ctr < nList.Count; ctr++) + { + if (!nList[ctr].Equals(sList[ctr])) + { + match = false; + break; + } + } + } + else if (!prop.GetValue(specificNfi).Equals(prop.GetValue(nfi))) + { + match = false; + break; + } + } + if (match) + { + Console.WriteLine($"NumberFormatInfo object for '{name}' matches '{ci.Name}'"); + hasOneMatch = true; + } + } + if (!hasOneMatch) + Console.WriteLine($"NumberFormatInfo object for '{name}' --> No Match"); + + Console.WriteLine(); + } +} +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parse1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parse1.cs new file mode 100644 index 00000000000..1ccddbbfa61 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parse1.cs @@ -0,0 +1,40 @@ +// +using System; +using System.Globalization; + +public class ParseEx1 +{ + public static void Main() + { + String[] values = { "1,034,562.91", "9 532 978,07" }; + String[] cultureNames = { "en-US", "fr-FR", "" }; + + foreach (var value in values) + { + foreach (var cultureName in cultureNames) + { + CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName); + String name = culture.Name == "" ? "Invariant" : culture.Name; + try + { + Decimal amount = Decimal.Parse(value, culture); + Console.WriteLine($"'{value}' --> {amount} ({name})"); + } + catch (FormatException) + { + Console.WriteLine($"'{value}': FormatException ({name})"); + } + } + Console.WriteLine(); + } + } +} +// The example displays the following output: +// '1,034,562.91' --> 1034562.91 (en-US) +// '1,034,562.91': FormatException (fr-FR) +// '1,034,562.91' --> 1034562.91 (Invariant) +// +// '9 532 978,07': FormatException (en-US) +// '9 532 978,07' --> 9532978.07 (fr-FR) +// '9 532 978,07': FormatException (Invariant) +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parsepersisted.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parsepersisted.cs new file mode 100644 index 00000000000..23e05bd954e --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parsepersisted.cs @@ -0,0 +1,80 @@ +// +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Threading; + +public class ParsePersistedEx +{ + public static void Main() + { + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); + PersistData(); + + CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("pt-BR"); + RestoreData(); + } + + private static void PersistData() + { + // Define an array of floating-point values. + Double[] values = { 160325.972, 8631.16, 1.304e5, 98017554.385, + 8.5938287084321676e94 }; + Console.WriteLine("Original values: "); + foreach (var value in values) + Console.WriteLine(value.ToString("R", CultureInfo.InvariantCulture)); + + // Serialize an array of doubles to a file + StreamWriter sw = new StreamWriter(@".\NumericData.bin"); + for (int ctr = 0; ctr < values.Length; ctr++) + { + sw.Write(values[ctr].ToString("R")); + if (ctr < values.Length - 1) sw.Write("|"); + } + sw.Close(); + Console.WriteLine(); + } + + private static void RestoreData() + { + // Deserialize the data + StreamReader sr = new StreamReader(@".\NumericData.bin"); + String data = sr.ReadToEnd(); + sr.Close(); + + String[] stringValues = data.Split('|'); + List newValueList = new List(); + + foreach (var stringValue in stringValues) + { + try + { + newValueList.Add(Double.Parse(stringValue)); + } + catch (FormatException) + { + newValueList.Add(Double.NaN); + } + } + + Console.WriteLine("Restored values:"); + foreach (var newValue in newValueList) + Console.WriteLine(newValue.ToString("R", NumberFormatInfo.InvariantInfo)); + } +} +// The example displays the following output: +// Original values: +// 160325.972 +// 8631.16 +// 130400 +// 98017554.385 +// 8.5938287084321671E+94 +// +// Restored values: +// 160325972 +// 863116 +// 130400 +// 98017554385 +// 8.5938287084321666E+110 +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parseuser1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parseuser1.cs new file mode 100644 index 00000000000..662c8e55016 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parseuser1.cs @@ -0,0 +1,43 @@ +// +using System; +using System.Globalization; + +public class ParseUserEx +{ + public static void Main() + { + CultureInfo stdCulture = CultureInfo.GetCultureInfo("en-US"); + CultureInfo custCulture = CultureInfo.CreateSpecificCulture("en-US"); + + String value = "310,16"; + try + { + Console.WriteLine($"{stdCulture.Name} culture reflects user overrides: {stdCulture.UseUserOverride}"); + Decimal amount = Decimal.Parse(value, stdCulture); + Console.WriteLine($"'{value}' --> {amount.ToString(CultureInfo.InvariantCulture)}"); + } + catch (FormatException) + { + Console.WriteLine($"Unable to parse '{value}'"); + } + Console.WriteLine(); + + try + { + Console.WriteLine($"{custCulture.Name} culture reflects user overrides: {custCulture.UseUserOverride}"); + Decimal amount = Decimal.Parse(value, custCulture); + Console.WriteLine($"'{value}' --> {amount.ToString(CultureInfo.InvariantCulture)}"); + } + catch (FormatException) + { + Console.WriteLine($"Unable to parse '{value}'"); + } + } +} +// The example displays the following output: +// en-US culture reflects user overrides: False +// '310,16' --> 31016 +// +// en-US culture reflects user overrides: True +// '310,16' --> 310.16 +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/project.csproj b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/project.csproj new file mode 100644 index 00000000000..cb4ea68ebe3 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0 + enable + + + diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties1.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties1.cs new file mode 100644 index 00000000000..3be5c7e9cb8 --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties1.cs @@ -0,0 +1,41 @@ +// +using System; +using System.Globalization; + +public class PropertiesEx1 +{ + public static void Main() + { + string[] formatStrings = { "C2", "E1", "F", "G3", "N", + "#,##0.000", "0,000,000,000.0##" }; + CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); + Decimal[] values = { 1345.6538m, 1921651.16m }; + + foreach (var value in values) + { + foreach (var formatString in formatStrings) + { + string resultString = value.ToString(formatString, culture); + Console.WriteLine("{0,-18} --> {1}", formatString, resultString); + } + Console.WriteLine(); + } + } +} +// The example displays the following output: +// C2 --> $1,345.65 +// E1 --> 1.3E+003 +// F --> 1345.65 +// G3 --> 1.35E+03 +// N --> 1,345.65 +// #,##0.000 --> 1,345.654 +// 0,000,000,000.0## --> 0,000,001,345.654 +// +// C2 --> $1,921,651.16 +// E1 --> 1.9E+006 +// F --> 1921651.16 +// G3 --> 1.92E+06 +// N --> 1,921,651.16 +// #,##0.000 --> 1,921,651.160 +// 0,000,000,000.0## --> 0,001,921,651.16 +// diff --git a/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties2.cs b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties2.cs new file mode 100644 index 00000000000..dee3c390c4a --- /dev/null +++ b/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties2.cs @@ -0,0 +1,22 @@ +// +using System; + +public class PropertiesEx2 +{ + public static void Main() + { + Decimal[] values = { 1345.6538m, 1921651.16m }; + + foreach (var value in values) + { + string resultString = value.ToString(); + Console.WriteLine(resultString); + Console.WriteLine(); + } + } +} +// The example displays the following output: +// 1345.6538 +// +// 1921651.16 +// diff --git a/xml/System.Globalization/CompareOptions.xml b/xml/System.Globalization/CompareOptions.xml index 5adfea83721..8be87d3b364 100644 --- a/xml/System.Globalization/CompareOptions.xml +++ b/xml/System.Globalization/CompareOptions.xml @@ -88,7 +88,8 @@ The `StringSort` value can only be used with object that represents the The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Current1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewCurrent1.cs" id="Snippet1"::: You can get a object that represents the current UI culture in either of two ways: @@ -188,7 +188,7 @@ You can get a object that represents the The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current UI culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUI1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewCurrentUI1.cs" id="Snippet2"::: ### Set the current and current UI cultures @@ -200,11 +200,11 @@ To change the culture and UI culture of a thread, do the following: The following example retrieves the current culture. If it is anything other than the French (France) culture, it changes the current culture to French (France). Otherwise, it changes the current culture to French (Luxembourg). -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Change1.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewChange1.cs" id="Snippet3"::: The following example retrieves the current culture. If it is anything other the Slovenian (Slovenia) culture, it changes the current culture to Slovenian (Slovenia). Otherwise, it changes the current culture to Croatian (Croatia). -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/ChangeUI1.cs" id="Snippet4"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewChangeUI1.cs" id="Snippet4"::: ## Get all cultures @@ -212,31 +212,23 @@ You can retrieve an array of specific categories of cultures or of all the cultu The following example calls the method twice, first with the enumeration member to retrieve all custom cultures, and then with the enumeration member to retrieve all replacement cultures. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/GetCultures1.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewGetCultures1.cs" id="Snippet5"::: ## Culture and threads When a new application thread is started, its current culture and current UI culture are defined by the current system culture, and not by the current thread culture. The following example illustrates the difference. It sets the current culture and current UI culture of an application thread to the French (France) culture (fr-FR). If the current culture is already fr-FR, the example sets it to the English (United States) culture (en-US). It displays three random numbers as currency values and then creates a new thread, which, in turn, displays three more random numbers as currency values. But as the output from the example shows, the currency values displayed by the new thread do not reflect the formatting conventions of the French (France) culture, unlike the output from the main application thread. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/defaultthread1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overviewdefaultthread1.cs" id="Snippet1"::: You can set the culture and UI culture of all threads in an application domain by assigning a object that represents that culture to the and properties. The following example uses these properties to ensure that all threads in the default application domain share the same culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/setthreads1.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overviewsetthreads1.cs" id="Snippet3"::: > [!WARNING] > Although the and properties are static members, they define the default culture and default UI culture only for the application domain that is current at the time these property values are set. For more information, see the next section, [Culture and application domains](#culture-and-application-domains). When you assign values to the and properties, the culture and UI culture of the threads in the application domain also change if they have not explicitly been assigned a culture. However, these threads reflect the new culture settings only while they execute in the current application domain. If these threads execute in another application domain, their culture becomes the default culture defined for that application domain. As a result, we recommend that you always set the culture of the main application thread, and not rely on the and properties to change it. -## Culture and application domains - - and are static properties that explicitly define a default culture only for the application domain that is current when the property value is set or retrieved. The following example sets the default culture and default UI culture in the default application domain to French (France), and then uses the class and the delegate to set the default culture and UI culture in a new application domain to Russian (Russia). A single thread then executes two methods in each application domain. Note that the thread's culture and UI culture are not explicitly set; they are derived from the default culture and UI culture of the application domain in which the thread is executing. Note also that the and properties return the default values of the application domain that is current when the method call is made. - -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/appdomainex1.cs" id="Snippet1"::: - -For more information about cultures and application domains, see the "Application Domains and Threads" section in the [Application Domains](/dotnet/framework/app-domains/application-domains) topic. - ## Culture and task-based asynchronous operations The [task-based asynchronous programming pattern](/dotnet/standard/parallel-programming/task-based-asynchronous-programming) uses and objects to asynchronously execute delegates on thread pool threads. The specific thread on which a particular task runs is not known in advance, but is determined only at runtime. @@ -251,7 +243,7 @@ The following example provides a simple illustration. The example defines a and are per-app domain properties; that is, they establish a default culture for all threads not explicitly assigned a culture in a specific application domain. However, for apps that target .NET Framework 4.6 or later, the culture of the calling thread remains part of an asynchronous task's context even if the task crosses app domain boundaries. @@ -786,7 +778,8 @@ If `name` is , the constr , for example, when the user modifies the regional and language options portion of Control Panel. However, the class does not automatically detect changes in the system settings. + +Information, such as the default culture and format patterns, is cached the first time it's requested. That information can change, for example, when the user modifies the regional and language options portion of Control Panel. However, the class does not automatically detect changes in the system settings. The method clears the cache of objects created by and refreshes the information in the , , and properties, based on the current system settings. diff --git a/xml/System.Globalization/NumberFormatInfo.xml b/xml/System.Globalization/NumberFormatInfo.xml index 3bf620eb5dc..8f04d106d1d 100644 --- a/xml/System.Globalization/NumberFormatInfo.xml +++ b/xml/System.Globalization/NumberFormatInfo.xml @@ -99,7 +99,7 @@ You can instantiate a object for th The following example uses these three ways to create objects that represent the formatting conventions of the current culture. It also retrieves the value of the property to illustrate that each object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate1.cs" id="Snippet1"::: You can create a writable object that represents the conventions of the current culture in any of the following ways: @@ -109,11 +109,11 @@ You can create a writable object th The following example illustrates these two ways of instantiating a object, and displays the value of its property to illustrate that the object is not read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate2.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate2.cs" id="Snippet2"::: Note that the Windows operating system allows the user to override some of the property values used in numeric formatting and parsing operations through the **Region and Language** item in Control Panel. For example, a user whose culture is English (United States) might choose to display currency values as 1.1 USD instead of the default of $1.1. The objects retrieved in the ways discussed previously all reflect these user overrides. If this is undesirable, you can create a object that does not reflect user overrides (and that is also read/write rather than read-only) by calling the constructor and supplying a value of `false` for the `useUserOverride` argument. The following example provides an illustration for a system whose current culture is English (United States) and whose currency symbol has been changed from the default of $ to USD. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate3.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate3.cs" id="Snippet3"::: If the property is set to `true`, the properties , , and are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the object (for example, if the selected calendar is not one of the calendars listed by the property), the results of the methods and the values of the properties are undefined. @@ -131,7 +131,7 @@ You can instantiate a object that r The following example uses each of these methods to instantiate a object that represents the invariant culture. It then indicates whether the object is read-only, -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate4.cs" id="Snippet4"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate4.cs" id="Snippet4"::: ### Instantiate a NumberFormatInfo object for a specific culture @@ -147,7 +147,7 @@ A specific culture represents a language that is spoken in a particular country/ The following example uses these four ways to create a object that reflects the formatting conventions of the Indonesian (Indonesia) culture. It also indicates whether each object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate5.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate5.cs" id="Snippet5"::: ### Instantiate a NumberFormatInfo object for a neutral culture @@ -157,7 +157,7 @@ However, because it is independent of a specific country/region, a neutral cultu You can use code like the following to determine which specific culture's formatting conventions each neutral culture represents. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/instantiate6.cs" id="Snippet6"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate6.cs" id="Snippet6"::: ## Dynamic data @@ -206,7 +206,7 @@ If an implementation is not provided to a formatti The following example illustrates the relationship between the interface and the class in formatting operations by defining a custom implementation. Its method displays the type name of the object requested by the formatting operation. If the interface is requesting a object, this method provides the object for the current culture. As the output from the example shows, the method requests a object to provide formatting information, whereas the method requests and objects as well as an implementation. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/formatprovider1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewformatprovider1.cs" id="Snippet1"::: If an implementation is not explicitly provided in a numeric formatting method call, the method calls the `CultureInfo.CurrentCulture.GetFormat` method, which returns the object that corresponds to the current culture. @@ -214,11 +214,11 @@ If an implementation is not explicitly provided in Every formatting operation uses either a standard or a custom numeric format string to produce a result string from a number. In some cases, the use of a format string to produce a result string is explicit, as in the following example. This code calls the method to convert a value to a number of different string representations by using the formatting conventions of the en-US culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/properties1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewproperties1.cs" id="Snippet2"::: In other cases, the use of a format string is implicit. For example, in the following method calls to the default or parameterless method, the value of the instance is formatted by using the general ("G") format specifier and the conventions of the current culture, which in this case is the en-US culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/properties2.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewproperties2.cs" id="Snippet3"::: Each standard numeric format string uses one or more properties to determine the pattern or the symbols used in the result string. Similarly, each custom numeric format specifier except "0" and "#" insert symbols in the result string that are defined by properties. The following table lists the standard and custom numeric format specifiers and their associated properties. To change the appearance of the result string for a particular culture, see the [Modify NumberFormatInfo properties](#modify-numberformatinfo-properties) section. For details about the use of these format specifiers, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). @@ -260,13 +260,13 @@ The following sections provide some examples. The following example modifies a object that represents the formatting conventions of the en-US culture. It assigns the ISO-4217 currency symbol to the property and defines a pattern for currency values that consists of the currency symbol followed by a space and a numeric value. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/customize_currency1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewcustomize_currency1.cs" id="Snippet1"::: ### Format a national identification number Many national identification numbers consist exclusively of digits and so can easily be formatted by modifying the properties of a object. For example, a social security number in the United States consists of 9 digits arranged as follows: `XXX-XX-XXXX`. The following example assumes that social security numbers are stored as integer values and formats them appropriately. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/customize_ssn1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewcustomize_ssn1.cs" id="Snippet2"::: ## Parse numeric strings @@ -278,7 +278,7 @@ The parsing methods also implicitly or explicitly use a object that also reflects user settings (overrides), the parsing operation returns a correct result. However, when the string is parsed by a object that reflects standard en-US cultural settings, it mistakes the comma symbol for a group separator and returns an incorrect result. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/parseuser1.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewparseuser1.cs" id="Snippet5"::: ### Serialize and deserialize numeric data @@ -304,7 +304,7 @@ The following example illustrates what can happen when this principle is violate The data is then parsed by a thread that uses the culture-specific settings of the pt-BR culture. In this case, although each parsing operation succeeds, the data doesn't round-trip successfully and data corruption occurs. In other cases, a parsing operation could fail and a exception could be thrown. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/parsepersisted.cs" id="Snippet6"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewparsepersisted.cs" id="Snippet6"::: ## Example The following example shows how to retrieve a object for a corresponding object, and use the retrieved object to query number formatting information for the particular culture. diff --git a/xml/System.Globalization/RegionInfo.xml b/xml/System.Globalization/RegionInfo.xml index a53528621cf..b50ff4bffad 100644 --- a/xml/System.Globalization/RegionInfo.xml +++ b/xml/System.Globalization/RegionInfo.xml @@ -83,7 +83,7 @@ To instantiate a object, you pass the property values for three objects that represent Belgium. The first is instantiated from a region name (`BE`) only, while the second and third are instantiated from culture names (`fr-BE` for French (Belgium) and `nl-BE` for Dutch (Belgium), respectively). The example uses reflection to retrieve the property values of each object. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/RegionInfo/propertyvalues1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/RegionInfo/Overview/propertyvalues1.cs" id="Snippet2"::: In scenarios such as the following, use culture names instead of country/region names when you instantiate a object: From a0f06d0da93fce303b1f720ebf8b1ef3065da33c Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 4 Jun 2026 17:14:02 -0700 Subject: [PATCH 4/8] fix warnings --- xml/System.Globalization/CultureInfo.xml | 21 ++++++-------- xml/System.Globalization/NumberFormatInfo.xml | 28 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/xml/System.Globalization/CultureInfo.xml b/xml/System.Globalization/CultureInfo.xml index 4262feb061d..f99869bfd47 100644 --- a/xml/System.Globalization/CultureInfo.xml +++ b/xml/System.Globalization/CultureInfo.xml @@ -165,7 +165,7 @@ Except for the invariant culture, culture data is dynamic. This is true even for Every thread in a .NET application has a current culture and a current UI culture. The current culture determines the formatting conventions for dates, times, numbers, and currency values, the sort order of text, casing conventions, and the ways in which strings are compared. The current UI culture is used to retrieve culture-specific resources at runtime. > [!NOTE] -> For information on how the current and current UI culture is determined on a per-thread basis, see the [Culture and threads](#culture-and-threads) section. For information on how the current and current UI culture is determined on threads executing in a new application domain, and on threads that cross application domain boundaries, see the [Culture and application domains](#culture-and-application-domains) section. For information on how the current and current UI culture is determined on threads performing task-based asynchronous operations, see the [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations) section. +> For information on how the current and current UI culture is determined on a per-thread basis, see the [Culture and threads](#culture-and-threads) section. For information on how the current and current UI culture is determined on threads performing task-based asynchronous operations, see the [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations) section. For more detailed information on the current culture, see the property. For more detailed information on the current UI culture, see the property topic. @@ -178,7 +178,7 @@ You can get a object that represents the The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewCurrent1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/Current1.cs" id="Snippet1"::: You can get a object that represents the current UI culture in either of two ways: @@ -188,7 +188,7 @@ You can get a object that represents the The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current UI culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewCurrentUI1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/CurrentUI1.cs" id="Snippet2"::: ### Set the current and current UI cultures @@ -200,11 +200,11 @@ To change the culture and UI culture of a thread, do the following: The following example retrieves the current culture. If it is anything other than the French (France) culture, it changes the current culture to French (France). Otherwise, it changes the current culture to French (Luxembourg). -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewChange1.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/Change1.cs" id="Snippet3"::: The following example retrieves the current culture. If it is anything other the Slovenian (Slovenia) culture, it changes the current culture to Slovenian (Slovenia). Otherwise, it changes the current culture to Croatian (Croatia). -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewChangeUI1.cs" id="Snippet4"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/ChangeUI1.cs" id="Snippet4"::: ## Get all cultures @@ -212,20 +212,17 @@ You can retrieve an array of specific categories of cultures or of all the cultu The following example calls the method twice, first with the enumeration member to retrieve all custom cultures, and then with the enumeration member to retrieve all replacement cultures. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/OverviewGetCultures1.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/GetCultures1.cs" id="Snippet5"::: ## Culture and threads When a new application thread is started, its current culture and current UI culture are defined by the current system culture, and not by the current thread culture. The following example illustrates the difference. It sets the current culture and current UI culture of an application thread to the French (France) culture (fr-FR). If the current culture is already fr-FR, the example sets it to the English (United States) culture (en-US). It displays three random numbers as currency values and then creates a new thread, which, in turn, displays three more random numbers as currency values. But as the output from the example shows, the currency values displayed by the new thread do not reflect the formatting conventions of the French (France) culture, unlike the output from the main application thread. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overviewdefaultthread1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/defaultthread1.cs" id="Snippet1"::: You can set the culture and UI culture of all threads in an application domain by assigning a object that represents that culture to the and properties. The following example uses these properties to ensure that all threads in the default application domain share the same culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overviewsetthreads1.cs" id="Snippet3"::: - -> [!WARNING] -> Although the and properties are static members, they define the default culture and default UI culture only for the application domain that is current at the time these property values are set. For more information, see the next section, [Culture and application domains](#culture-and-application-domains). +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/setthreads1.cs" id="Snippet3"::: When you assign values to the and properties, the culture and UI culture of the threads in the application domain also change if they have not explicitly been assigned a culture. However, these threads reflect the new culture settings only while they execute in the current application domain. If these threads execute in another application domain, their culture becomes the default culture defined for that application domain. As a result, we recommend that you always set the culture of the main application thread, and not rely on the and properties to change it. @@ -243,7 +240,7 @@ The following example provides a simple illustration. The example defines a and are per-app domain properties; that is, they establish a default culture for all threads not explicitly assigned a culture in a specific application domain. However, for apps that target .NET Framework 4.6 or later, the culture of the calling thread remains part of an asynchronous task's context even if the task crosses app domain boundaries. diff --git a/xml/System.Globalization/NumberFormatInfo.xml b/xml/System.Globalization/NumberFormatInfo.xml index 8f04d106d1d..de0e769f165 100644 --- a/xml/System.Globalization/NumberFormatInfo.xml +++ b/xml/System.Globalization/NumberFormatInfo.xml @@ -99,7 +99,7 @@ You can instantiate a object for th The following example uses these three ways to create objects that represent the formatting conventions of the current culture. It also retrieves the value of the property to illustrate that each object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate1.cs" id="Snippet1"::: You can create a writable object that represents the conventions of the current culture in any of the following ways: @@ -109,11 +109,11 @@ You can create a writable object th The following example illustrates these two ways of instantiating a object, and displays the value of its property to illustrate that the object is not read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate2.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate2.cs" id="Snippet2"::: Note that the Windows operating system allows the user to override some of the property values used in numeric formatting and parsing operations through the **Region and Language** item in Control Panel. For example, a user whose culture is English (United States) might choose to display currency values as 1.1 USD instead of the default of $1.1. The objects retrieved in the ways discussed previously all reflect these user overrides. If this is undesirable, you can create a object that does not reflect user overrides (and that is also read/write rather than read-only) by calling the constructor and supplying a value of `false` for the `useUserOverride` argument. The following example provides an illustration for a system whose current culture is English (United States) and whose currency symbol has been changed from the default of $ to USD. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate3.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate3.cs" id="Snippet3"::: If the property is set to `true`, the properties , , and are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the object (for example, if the selected calendar is not one of the calendars listed by the property), the results of the methods and the values of the properties are undefined. @@ -131,7 +131,7 @@ You can instantiate a object that r The following example uses each of these methods to instantiate a object that represents the invariant culture. It then indicates whether the object is read-only, -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate4.cs" id="Snippet4"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate4.cs" id="Snippet4"::: ### Instantiate a NumberFormatInfo object for a specific culture @@ -147,7 +147,7 @@ A specific culture represents a language that is spoken in a particular country/ The following example uses these four ways to create a object that reflects the formatting conventions of the Indonesian (Indonesia) culture. It also indicates whether each object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate5.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate5.cs" id="Snippet5"::: ### Instantiate a NumberFormatInfo object for a neutral culture @@ -157,7 +157,7 @@ However, because it is independent of a specific country/region, a neutral cultu You can use code like the following to determine which specific culture's formatting conventions each neutral culture represents. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewinstantiate6.cs" id="Snippet6"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/instantiate6.cs" id="Snippet6"::: ## Dynamic data @@ -206,7 +206,7 @@ If an implementation is not provided to a formatti The following example illustrates the relationship between the interface and the class in formatting operations by defining a custom implementation. Its method displays the type name of the object requested by the formatting operation. If the interface is requesting a object, this method provides the object for the current culture. As the output from the example shows, the method requests a object to provide formatting information, whereas the method requests and objects as well as an implementation. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewformatprovider1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/formatprovider1.cs" id="Snippet1"::: If an implementation is not explicitly provided in a numeric formatting method call, the method calls the `CultureInfo.CurrentCulture.GetFormat` method, which returns the object that corresponds to the current culture. @@ -214,11 +214,11 @@ If an implementation is not explicitly provided in Every formatting operation uses either a standard or a custom numeric format string to produce a result string from a number. In some cases, the use of a format string to produce a result string is explicit, as in the following example. This code calls the method to convert a value to a number of different string representations by using the formatting conventions of the en-US culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewproperties1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties1.cs" id="Snippet2"::: In other cases, the use of a format string is implicit. For example, in the following method calls to the default or parameterless method, the value of the instance is formatted by using the general ("G") format specifier and the conventions of the current culture, which in this case is the en-US culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewproperties2.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/properties2.cs" id="Snippet3"::: Each standard numeric format string uses one or more properties to determine the pattern or the symbols used in the result string. Similarly, each custom numeric format specifier except "0" and "#" insert symbols in the result string that are defined by properties. The following table lists the standard and custom numeric format specifiers and their associated properties. To change the appearance of the result string for a particular culture, see the [Modify NumberFormatInfo properties](#modify-numberformatinfo-properties) section. For details about the use of these format specifiers, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). @@ -260,13 +260,13 @@ The following sections provide some examples. The following example modifies a object that represents the formatting conventions of the en-US culture. It assigns the ISO-4217 currency symbol to the property and defines a pattern for currency values that consists of the currency symbol followed by a space and a numeric value. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewcustomize_currency1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_currency1.cs" id="Snippet1"::: ### Format a national identification number Many national identification numbers consist exclusively of digits and so can easily be formatted by modifying the properties of a object. For example, a social security number in the United States consists of 9 digits arranged as follows: `XXX-XX-XXXX`. The following example assumes that social security numbers are stored as integer values and formats them appropriately. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewcustomize_ssn1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/customize_ssn1.cs" id="Snippet2"::: ## Parse numeric strings @@ -278,7 +278,7 @@ The parsing methods also implicitly or explicitly use a object that also reflects user settings (overrides), the parsing operation returns a correct result. However, when the string is parsed by a object that reflects standard en-US cultural settings, it mistakes the comma symbol for a group separator and returns an incorrect result. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewparseuser1.cs" id="Snippet5"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parseuser1.cs" id="Snippet5"::: ### Serialize and deserialize numeric data @@ -304,7 +304,7 @@ The following example illustrates what can happen when this principle is violate The data is then parsed by a thread that uses the culture-specific settings of the pt-BR culture. In this case, although each parsing operation succeeds, the data doesn't round-trip successfully and data corruption occurs. In other cases, a parsing operation could fail and a exception could be thrown. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overviewparsepersisted.cs" id="Snippet6"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/NumberFormatInfo/Overview/parsepersisted.cs" id="Snippet6"::: ## Example The following example shows how to retrieve a object for a corresponding object, and use the retrieved object to query number formatting information for the particular culture. From 91ac81b566db23a3a802b4846bfc7b0d44e9b385 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 4 Jun 2026 18:00:34 -0700 Subject: [PATCH 5/8] fix errors --- .../CultureInfo/CurrentCulture/Project.csproj | 8 - .../{ => Overview}/create1.cs | 0 .../{ => Overview}/create2.cs | 0 .../{ => Overview}/example1.cs | 0 .../{ => Overview}/example2.cs | 0 .../{ => Overview}/example3.cs | 0 .../{ => Overview}/example4.cs | 0 .../{ => Overview}/example5.cs | 0 .../{ => Overview}/formatprovider1.cs | 0 .../{ => Overview}/instantiate2.cs | 0 .../{ => Overview}/instantiate3.cs | 0 .../{ => Overview}/instantiate6.cs | 0 .../{ => Overview}/parse1.cs | 0 .../{ => Overview}/parse2.cs | 0 .../{ => Overview}/project.csproj | 0 .../{ => Overview}/serialize1.cs | 0 .../{ => Overview}/serialize2.cs | 0 .../CurrentCulture/currentculture.vb | 4 +- .../CurrentCulture/currentculture.vbproj | 9 - .../DateTimeFormatInfo.xml | 158 +++++++++--------- 20 files changed, 81 insertions(+), 98 deletions(-) delete mode 100644 snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/create1.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/create2.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/example1.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/example2.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/example3.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/example4.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/example5.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/formatprovider1.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/instantiate2.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/instantiate3.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/instantiate6.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/parse1.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/parse2.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/project.csproj (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/serialize1.cs (100%) rename snippets/csharp/System.Globalization/DateTimeFormatInfo/{ => Overview}/serialize2.cs (100%) delete mode 100644 snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vbproj diff --git a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj b/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj deleted file mode 100644 index 874c98f3477..00000000000 --- a/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Project.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Library - net10.0 - - - diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create1.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create1.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create2.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create2.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example1.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example1.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example2.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example2.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example3.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example3.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example4.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example4.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example5.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/example5.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example5.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/formatprovider1.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/formatprovider1.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate2.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate2.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate3.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate3.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate6.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate6.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse1.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse1.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse2.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse2.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/project.csproj similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/project.csproj rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/project.csproj diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize1.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize1.cs diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize2.cs similarity index 100% rename from snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs rename to snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize2.cs diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb index 8502244c8a8..82d751853f4 100644 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb @@ -2,7 +2,7 @@ Imports System.Globalization Imports System.Threading -Public Module Example +Public Module Example2 Public Sub Main() ' Display the name of the current culture. @@ -18,7 +18,7 @@ Public Module Example ' Change the current UI culture to ja-JP. CultureInfo.CurrentUICulture = New CultureInfo("ja-JP", False) Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name) - End Sub + End Sub End Module ' The example displays the following output: ' CurrentCulture is en-US. diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vbproj b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vbproj deleted file mode 100644 index 87f6a03920d..00000000000 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vbproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - CurrentCulture - net6.0 - - - diff --git a/xml/System.Globalization/DateTimeFormatInfo.xml b/xml/System.Globalization/DateTimeFormatInfo.xml index ed9380c6d42..fd5513deb80 100644 --- a/xml/System.Globalization/DateTimeFormatInfo.xml +++ b/xml/System.Globalization/DateTimeFormatInfo.xml @@ -104,7 +104,7 @@ The invariant culture represents a culture that is culture-insensitive. It is ba The following example uses each of these methods to instantiate a object that represents the invariant culture. It then indicates whether the object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create1.cs" id="Snippet1"::: ### Instantiate a DateTimeFormatInfo object for a specific culture @@ -120,19 +120,19 @@ A specific culture represents a language that is spoken in a particular country/ The following example illustrates each of these ways to instantiate a object and indicates whether the resulting object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create1.cs" id="Snippet3"::: ### Instantiate a DateTimeFormatInfo object for a neutral culture A neutral culture represents a culture or language that is independent of a country/region; it is typically the parent of one or more specific cultures. For example, Fr is a neutral culture for the French language and the parent of the fr-FR culture. You can instantiate a object that represents the formatting conventions of a neutral culture in the same ways that you create a object that represents the formatting conventions of a specific culture. In addition, you can retrieve a neutral culture's object by retrieving a neutral culture from a specific culture's property and retrieving the object returned by its property. Unless the parent culture represents the invariant culture, the returned object is read/write. The following example illustrates these ways of instantiating a object that represents a neutral culture. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create1.cs" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create1.cs" id="Snippet2"::: However, a neutral culture lacks culture-specific formatting information, because it is independent of a specific country/region. Instead of populating the object with generic values, .NET returns a object that reflects the formatting conventions of a specific culture that is a child of the neutral culture. For example, the object for the neutral en culture reflects the formatting conventions of the en-US culture, and the object for the fr culture reflects the formatting conventions of the fr-FR culture. You can use code like the following to determine which specific culture's formatting conventions a neutral culture represents. The example uses reflection to compare the properties of a neutral culture with the properties of a specific child culture. It considers two calendars to be equivalent if they are the same calendar type and, for Gregorian calendars, if their properties have identical values. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate6.cs" id="Snippet6"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate6.cs" id="Snippet6"::: ### Instantiate a DateTimeFormatInfo object for the current culture @@ -146,7 +146,7 @@ You can instantiate a object that The following example uses each of these methods to instantiate a object that represents the formatting conventions of the current culture. It then indicates whether the object is read-only. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/create2.cs" id="Snippet4"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/create2.cs" id="Snippet4"::: You can create a writable object that represents the conventions of the current culture in one of these ways: @@ -156,11 +156,11 @@ You can create a writable object The following example illustrates each way of instantiating a read/write object and displays the value of its property. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate2.cs" id="Snippet7"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate2.cs" id="Snippet7"::: In Windows, the user can override some of the property values used in formatting and parsing operations through the **Region and Language** application in Control Panel. For example, a user whose culture is English (United States) might choose to display long time values using a 24-hour clock (in the format HH:mm:ss) instead of the default 12-hour clock (in the format h:mm:ss tt). The objects retrieved in the ways discussed previously all reflect these user overrides. If this is undesirable, you can create a object that does not reflect user overrides (and is also read/write instead of read-only) by calling the constructor and supplying a value of `false` for the `useUserOverride` argument. The following example illustrates this for a system whose current culture is English (United States) and whose long time pattern has been changed from the default of h:mm:ss tt to HH:mm:ss. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/instantiate3.cs" id="Snippet8"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/instantiate3.cs" id="Snippet8"::: ## DateTimeFormatInfo and dynamic data @@ -206,7 +206,7 @@ If an implementation is not provided to a formatti The following example illustrates the relationship between the interface and the class in formatting operations. It defines a custom implementation whose method displays the type of the object requested by the formatting operation. If it is requesting a object, the method provides the object for the current culture. As the output from the example shows, the method requests a object to provide formatting information, whereas the method requests and objects as well as an implementation. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/formatprovider1.cs" id="Snippet9"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/formatprovider1.cs" id="Snippet9"::: ## Format strings and DateTimeFormatInfo properties @@ -266,19 +266,19 @@ There are two other ways to change the format of a result string: The following example changes the format of a result string produced by the "d" (short date) standard format string. It changes the associated property for the en-US or English (United States) culture from its default of "M/d/yyyy" to "yyyy'-"MM"-"dd" and uses the "d" standard format string to display the date both before and after the property is changed. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example1.cs" id="Snippet10"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example1.cs" id="Snippet10"::: ### Change the date separator character The following example changes the date separator character in a object that represents the formatting conventions of the fr-FR culture. The example uses the "g" standard format string to display the date both before and after the property is changed. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example3.cs" id="Snippet12"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example3.cs" id="Snippet12"::: ### Change day name abbreviations and the long date pattern In some cases, the long date pattern, which typically displays the full day and month name along with the number of the day of the month and the year, may be too long. The following example shortens the long date pattern for the en-US culture to return a one-character or two-character day name abbreviation followed by the day number, the month name abbreviation, and the year. It does this by assigning shorter day name abbreviations to the array, and by modifying the custom format string assigned to the property. This affects the result strings returned by the "D" and "f" standard format strings. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example2.cs" id="Snippet13"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example2.cs" id="Snippet13"::: Ordinarily, the change to the property also affects the property, which in turn defines the result string returned by the "F" standard format string. To preserve the original full date and time pattern, the example reassigns the original custom format string assigned to the property after the property is modified. @@ -286,7 +286,7 @@ Ordinarily, the change to the \s*t+\s*)? (?(openAMPM) h+(?[^ht]+)$ | \s*h+(?[^ht]+)\s*t+)` is defined as follows: @@ -391,7 +391,7 @@ The following example adds the "g" custom format specifier to the object. The class supports a single era, which it names A.D. (Anno Domini). The example changes the era name to C.E. (Common Era) by replacing the "g" custom format specifier in the format string assigned to the property with a literal string. The use of a literal string is necessary, because the era name is typically returned by the method from private data in the culture tables supplied by either .NET or the operating system. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/example4.cs" id="Snippet11"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/example4.cs" id="Snippet11"::: ## Parse date and time strings @@ -403,7 +403,7 @@ The parsing methods also implicitly or explicitly use a exception in the other three cultures because 18 is interpreted as the month number. 1/2/2015 is parsed as the second day of the first month in the en-US culture, but as the first day of the second month in the remaining cultures. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse1.cs" id="Snippet15"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse1.cs" id="Snippet15"::: Date and time strings are typically parsed for two reasons: @@ -418,7 +418,7 @@ When you parse date and time strings input by the user, you should always instan The following example illustrates the difference between a parsing operation that reflects user cultural settings and one that does not. In this case, the default system culture is en-US, but the user has used Control Panel, **Region and Language** to change the short date pattern from its default of "M/d/yyyy" to "yy/MM/dd". When the user enters a string that reflects user settings, and the string is parsed by a object that also reflects user settings (overrides), the parsing operation returns a correct result. However, when the string is parsed by a object that reflects standard en-US cultural settings, the parsing method throws a exception because it interprets 14 as the number of the month, not the last two digits of the year. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/parse2.cs" id="Snippet16"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/parse2.cs" id="Snippet16"::: ### Serialize and deserialize date and time data @@ -428,11 +428,11 @@ If the time component of a date and time value is significant, it should also be The following example illustrates the process of round-tripping a date and time value. It serializes a date and time on a system that observes U.S. Pacific time and whose current culture is en-US. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize1.cs" id="Snippet17"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize1.cs" id="Snippet17"::: It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Paris time zone and whose current culture is fr-FR. The restored date is nine hours later than the original date, which reflects the time zone adjustment from eight hours behind UTC to one hour ahead of UTC. Both the original date and the restored date represent the same moment in time. -:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/serialize2.cs" id="Snippet18"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/serialize2.cs" id="Snippet18"::: ]]> @@ -441,8 +441,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par The following example uses reflection to get the properties of the object for the English (United States) culture. It displays the value of those properties that contain custom format strings and uses those strings to display formatted dates. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/format1.vb" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/Overview/format1.cs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/Overview/format1.vb" id="Snippet5"::: ]]> @@ -560,8 +560,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated day names to its property. It then uses the "ddd" format specifier in a [custom date and time format string](/dotnet/standard/base-types/custom-date-and-time-format-strings) to display the string representation of dates for one week beginning May 28, 2014. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedDayNames/abbreviateddaynames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedDayNames/abbreviateddaynames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedDayNames/abbreviateddaynames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedDayNames/abbreviateddaynames1.vb" id="Snippet1"::: ]]> @@ -629,8 +629,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated genitive month names to its and properties. It then displays the string representation of dates that include the abbreviated month name of each month in the culture's supported calendar. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: ]]> @@ -701,8 +701,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated genitive month names to its and properties. It then displays the string representation of dates that include the abbreviated name of each month in the culture's supported calendar. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: ]]> @@ -835,8 +835,8 @@ Changing the value of this property affects the following properties as well: object that represents the Arabic (Egypt) culture and first attempts to change its calendar to the Japanese calendar. Because the Japanese calendar is not supported, the method makes not change the culture's calendar. However, because the Umm al-Qura calendar is a member of the collection, the method does succeed in making it the current calendar for the ar-EG culture. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Calendar/CalendarTest1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Calendar/CalendarTest1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/Calendar/CalendarTest1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/Calendar/CalendarTest1.vb" id="Snippet1"::: ]]>
@@ -1019,8 +1019,8 @@ Changing the value of this property affects the following properties as well: property to retrieve a object that represents the formatting conventions of the current culture, which in this case is the en-US culture. It then displays the format string and the result string for six formatting properties. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/CurrentInfo/CurrentInfo1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/CurrentInfo/CurrentInfo1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/CurrentInfo/CurrentInfo1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/CurrentInfo/CurrentInfo1.vb" id="Snippet1"::: ]]>
@@ -1080,8 +1080,8 @@ Changing the value of this property affects the following properties as well: object for the en-US culture, changes its date separator to "-", and displays a date by using the "d", "G", and "g" standard format strings. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/DateSeparator/dateseparatorex.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/DateSeparator/dateseparatorex.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/DateSeparator/dateseparatorex.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/DateSeparator/dateseparatorex.vb" id="Snippet1"::: ]]>
@@ -1274,8 +1274,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/FullDateTimePattern/dtfi_fulldatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/FullDateTimePattern/dtfi_fulldatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/FullDateTimePattern/dtfi_fulldatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/FullDateTimePattern/dtfi_fulldatetimepattern.vb" id="Snippet1"::: ]]>
@@ -1575,8 +1575,8 @@ This property is affected if the value of the method in formatting operations. However, if you do, the string representation of a date and time value returned in that formatting operation cannot always be parsed successfully by the `Parse` and `TryParse` methods. Therefore, you cannot assume that the custom format strings returned by the method can be used to round-trip date and time values. The following example illustrates this problem. It retrieves a object that contains formatting information for the Italy (Italian) culture. It passes each custom format string in the array returned by the method to the method to create the string representation of a date and time. This example then attempts to parse this value by calling the method. As the output from the example shows, some of the custom format strings do not produce a date and time value that successfully round-trips. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex1.vb" id="Snippet1"::: To parse the string representation of a date and time that can be expressed in a number of predefined custom formats, call one of the following methods: @@ -1593,8 +1593,8 @@ This property is affected if the value of the object that represents the invariant culture by calling the constructor. It could also retrieve a that represents the invariant culture from the property. @@ -1657,8 +1657,8 @@ This property is affected if the value of the method in formatting operations. However, if you do, the string representation of a date and time value returned in that formatting operation cannot always be parsed successfully by the `Parse` and `TryParse` methods. Therefore, you cannot assume that the custom format strings returned by the method can be used to round-trip date and time values. The following example illustrates this problem. It retrieves a object that contains formatting information for the Russia (Russian) culture. It calls the method for each standard format string, and then passes each custom format string in the returned array to the method to create the string representation of a date and time. This example then attempts to parse this value by calling the method. As the output from the example shows, some of the custom format strings do not produce a date and time value that successfully round-trips. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex2.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex2.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex2.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex2.vb" id="Snippet2"::: To parse the string representation of a date and time that can be expressed in a number of predefined custom formats, call one of the following methods: @@ -1675,8 +1675,8 @@ This property is affected if the value of the @@ -1824,8 +1824,8 @@ This property is affected if the value of the ignores the punctuation in the era name, only if the calendar is Gregorian and the culture uses the era name "A.D.". - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetEra/gregorian_getera.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetEra/gregorian_getera.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetEra/gregorian_getera.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetEra/gregorian_getera.vb" id="Snippet1"::: ]]> @@ -2181,8 +2181,8 @@ This property is affected if the value of the @@ -2344,8 +2344,8 @@ This property is affected if the value of the property defines the culture-specific format of date strings that are returned by calls to the and methods and by composite format strings that are supplied the "D" standard format string. The following example illustrates the relationships among the following: the "D" standard format string, the custom format string returned by the property, and the culture-specific representation of a date. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern1.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern1.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern1.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern1.vb" id="Snippet2"::: See [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) for individual custom format specifiers that can be combined to construct custom format strings such as "dddd, dd MMMM yyyy". @@ -2353,14 +2353,14 @@ This property is affected if the value of the property of a object that represents the Arabic (Syria) culture changes when the object used by the culture changes. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern2.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern2.vb" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern2.cs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern2.vb" id="Snippet3"::: ## Examples The following example displays the value of the property for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/dtfi_longdatepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/dtfi_longdatepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/dtfi_longdatepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/dtfi_longdatepattern.vb" id="Snippet1"::: ]]> @@ -2425,8 +2425,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongTimePattern/dtfi_longtimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongTimePattern/dtfi_longtimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongTimePattern/dtfi_longtimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongTimePattern/dtfi_longtimepattern.vb" id="Snippet1"::: ]]> @@ -2493,8 +2493,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/MonthDayPattern/dtfi_monthdaypattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/MonthDayPattern/dtfi_monthdaypattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/MonthDayPattern/dtfi_monthdaypattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/MonthDayPattern/dtfi_monthdaypattern.vb" id="Snippet1"::: ]]> @@ -2558,8 +2558,8 @@ This property is affected if the value of the @@ -2684,8 +2684,8 @@ This property is affected if the value of the @@ -2871,8 +2871,8 @@ This property is affected if the value of the @@ -2942,8 +2942,8 @@ This property is affected if the value of the object that represents the "en-US" (English - United States) culture and uses it to parse an array of date and time strings using the "Y" standard format string. It then uses the method to associate a new custom format string with the "Y" standard format string, and then attempts to parse the array of date and time strings. Output from the example demonstrates that the new custom format string is used in both the parsing and formatting operations. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/SetAllDateTimePatterns/setalldatetimepatterns.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/SetAllDateTimePatterns/setalldatetimepatterns.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/SetAllDateTimePatterns/setalldatetimepatterns.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/SetAllDateTimePatterns/setalldatetimepatterns.vb" id="Snippet1"::: ]]> @@ -3016,13 +3016,13 @@ This property is affected if the value of the property and the value of a date formatted using the property for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortDatePattern/dtfi_shortdatepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortDatePattern/dtfi_shortdatepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/dtfi_shortdatepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/dtfi_shortdatepattern.vb" id="Snippet1"::: The following example modifies the property of a object that represents the formatting conventions of the English (United States) culture. It also displays a date value twice, first to reflect the original property and then to reflect the new property value. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortDatePattern/shortdatepattern1.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortDatePattern/shortdatepattern1.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/shortdatepattern1.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/shortdatepattern1.vb" id="Snippet2"::: ]]> @@ -3085,8 +3085,8 @@ The default array starts on Sunday. ## Examples The following example demonstrates several methods and properties that specify date and time format patterns, native calendar name, and full and abbreviated month and day names. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetShortestDayName/dtfi1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetShortestDayName/dtfi1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetShortestDayName/dtfi1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetShortestDayName/dtfi1.vb" id="Snippet1"::: ]]> @@ -3150,8 +3150,8 @@ The default array starts on Sunday. ## Examples The following example displays the value of for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortTimePattern/dtfi_shorttimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortTimePattern/dtfi_shorttimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortTimePattern/dtfi_shorttimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortTimePattern/dtfi_shorttimepattern.vb" id="Snippet1"::: ]]> @@ -3216,8 +3216,8 @@ The default array starts on Sunday. ## Examples The following example displays the value of for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/SortableDateTimePattern/dtfi_sortabledatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/SortableDateTimePattern/dtfi_sortabledatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/SortableDateTimePattern/dtfi_sortabledatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/SortableDateTimePattern/dtfi_sortabledatetimepattern.vb" id="Snippet1"::: ]]> @@ -3283,8 +3283,8 @@ If the custom pattern includes the format pattern ":", object for the en-US culture, changes its date separator to ".", and displays a date by using the "t", "T", "F", "f", "G", and "g" standard format strings. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/TimeSeparator/timeseparatorex.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/TimeSeparator/timeseparatorex.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/TimeSeparator/timeseparatorex.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/TimeSeparator/timeseparatorex.vb" id="Snippet1"::: ]]> @@ -3350,8 +3350,8 @@ If the custom pattern includes the format pattern ":", for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.vb" id="Snippet1"::: ]]> @@ -3417,8 +3417,8 @@ If the custom pattern includes the format pattern ":", for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/YearMonthPattern/dtfi_yearmonthpattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/YearMonthPattern/dtfi_yearmonthpattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/YearMonthPattern/dtfi_yearmonthpattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/YearMonthPattern/dtfi_yearmonthpattern.vb" id="Snippet1"::: ]]> From 02ff013585b58006272abd2a97bed2204063b326 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 4 Jun 2026 18:08:39 -0700 Subject: [PATCH 6/8] fix compile errors --- .../DateTimeFormatInfo/Overview/format1.cs | 4 ++-- .../CultureInfo/CurrentCulture/currentculture.vb | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs index 1ae0f4db898..7851520ed50 100644 --- a/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs +++ b/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs @@ -3,9 +3,9 @@ using System.Globalization; using System.Reflection; -public class Example +public class FormatExample1 { - public static void Main() + public static void Run() { // Get the properties of an en-US DateTimeFormatInfo object. DateTimeFormatInfo dtfi = CultureInfo.GetCultureInfo("en-US").DateTimeFormat; diff --git a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb index 82d751853f4..b0159e4e09e 100644 --- a/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb +++ b/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/currentculture.vb @@ -3,8 +3,7 @@ Imports System.Globalization Imports System.Threading Public Module Example2 - Public Sub Main() - + Public Sub Run() ' Display the name of the current culture. Console.WriteLine("CurrentCulture is {0}.", CultureInfo.CurrentCulture.Name) From 9c0c621a8d5d9cf7fc8e613977cede56597d4821 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 5 Jun 2026 11:55:44 -0700 Subject: [PATCH 7/8] respond to ccr --- xml/System.Globalization/CultureInfo.xml | 10 +- .../DateTimeFormatInfo.xml | 94 ++----------------- xml/System.Globalization/PersianCalendar.xml | 2 +- xml/System.IO/FileSystemWatcher.xml | 17 ++-- 4 files changed, 20 insertions(+), 103 deletions(-) diff --git a/xml/System.Globalization/CultureInfo.xml b/xml/System.Globalization/CultureInfo.xml index f99869bfd47..d7f5b278b00 100644 --- a/xml/System.Globalization/CultureInfo.xml +++ b/xml/System.Globalization/CultureInfo.xml @@ -142,7 +142,7 @@ On Windows, you can create custom locales. For more information, see [Custom loc .NET derives its cultural data from a one of a variety of sources, depending on implementation, platform, and version: - In all versions of .NET (Core) running on Unix platforms or Windows 10 and later versions, cultural data is provided by the [International Components for Unicode (ICU) Library](https://icu.unicode.org/). The specific version of the ICU Library depends on the individual operating system. -- In all versions of .NET (Core) running on Windows 9 and earlier versions, cultural data is provided by the Windows operating system. +- In all versions of .NET (Core) running on Windows 8.1 and earlier versions, cultural data is provided by the Windows operating system. - In .NET Framework 4 and later versions, cultural data is provided by the Windows operating system. Because of this, a culture available on a particular .NET implementation, platform, or version may not be available on a different .NET implementation, platform, or version. @@ -174,7 +174,7 @@ For more detailed information on the current culture, see the object that represents the current culture in either of two ways: - By retrieving the value of the property. -- By retrieving the value of the [Thread.CurrentThread.CurrentCulture]() property. +- By retrieving the value of the [Thread.CurrentThread.CurrentCulture](xref:System.Threading.Thread.CurrentCulture) property. The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current culture. @@ -184,7 +184,7 @@ You can get a object that represents the - By retrieving the value of the property. -- By retrieving the value of the [Thread.CurrentThread.CurrentUICulture]() property. +- By retrieving the value of the [Thread.CurrentThread.CurrentUICulture](xref:System.Threading.Thread.CurrentUICulture) property. The following example retrieves both property values, compares them to show that they are equal, and displays the name of the current UI culture. @@ -1140,7 +1140,7 @@ When a thread is started, its culture is initially determined as follows: :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb" id="Snippet14"::: - For more information, see [Culture and task-based asynchronous operations](system-globalization-cultureinfo.md#culture-and-task-based-asynchronous-operations). + For more information, see [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations). - By calling the `GetUserDefaultLocaleName` function on Windows or the `uloc_getDefault` function from [ICU](https://icu-project.org/), which currently calls the POSIX `setlocale` function with category `LC_MESSAGES`, on Unix-like systems. @@ -1270,7 +1270,7 @@ The property is a per-t :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb" id="Snippet14"::: - For more information, see the "Culture and task-based asynchronous operations" section in the documentation. + For more information, see [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations). - By calling the Windows `GetUserDefaultUILanguage` function. diff --git a/xml/System.Globalization/DateTimeFormatInfo.xml b/xml/System.Globalization/DateTimeFormatInfo.xml index fd5513deb80..b1604f80008 100644 --- a/xml/System.Globalization/DateTimeFormatInfo.xml +++ b/xml/System.Globalization/DateTimeFormatInfo.xml @@ -290,92 +290,12 @@ For many cultures in .NET, the time is expressed by using a 12-hour clock and an The example uses a regular expression to modify the format string. The regular expression pattern `@"^(?\s*t+\s*)? (?(openAMPM) h+(?[^ht]+)$ | \s*h+(?[^ht]+)\s*t+)` is defined as follows: -|Pattern|Description| -|-------------|-----------------| -|`^`|Begin the match at the beginning of the string.| -|`(?\s*t+\s*)?`|Match zero or one occurrence of zero or more white-space characters, followed by the letter "t" one or more times, followed by zero or more white-space characters. This capturing group is named `openAMPM`.| -|`(?(openAMPM) h+(?[^ht]+) - - - - - - - - - - - - - System.Globalization - 4.0.0.0 - 4.0.10.0 - - - mscorlib - 1.0.5000.0 - 2.0.0.0 - 2.0.5.0 - 4.0.0.0 - - - netstandard - 2.0.0.0 - 2.1.0.0 - - - System.Runtime - 4.2.0.0 - 4.2.1.0 - 4.2.2.0 - 5.0.0.0 - 6.0.0.0 - 7.0.0.0 - 8.0.0.0 - 9.0.0.0 - 10.0.0.0 - 11.0.0.0 - - - - - - - - - - - - - - - - - - - - - - System.Object - - - - System.ICloneable - - - System.IFormatProvider - - - - - [System.Runtime.CompilerServices.Nullable(0)] - [<System.Runtime.CompilerServices.Nullable(0)>] - - - - Provides culture-specific information about the format of date and time values. -|If the `openAMPM` group has a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t". The match ends at the end of the string. All characters captured after "h" are included in a capturing group named `nonHours`.| -|`| \s*h+(?[^ht]+)\s*t+)`|If the `openAMPM` group does not have a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t", followed by zero or more white-space characters. Finally, match one or more occurrences of the letter "t". All characters captured after "h" and before the white-spaces and "t" are included in a capturing group named `nonHours`.| +| Pattern | Description | +|--------------------------|-------------------------------------------------| +| `^` | Begin the match at the beginning of the string. | +| `(?\s*t+\s*)?` | Match zero or one occurrence of zero or more white-space characters, followed by the letter "t" one or more times, followed by zero or more white-space characters. This capturing group is named `openAMPM`. | +| `(?(openAMPM) h+(?[^ht]+)$` | If the `openAMPM` group has a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t". The match ends at the end of the string. All characters captured after "h" are included in a capturing group named `nonHours`. | +| `| \s*h+(?[^ht]+)\s*t+)` | If the `openAMPM` group does not have a match, match the letter "h" one or more times, followed by one or more characters that are neither "h" nor "t", followed by zero or more white-space characters. Finally, match one or more occurrences of the letter "t". All characters captured after "h" and before the white-spaces and "t" are included in a capturing group named `nonHours`. | The `nonHours` capturing group contains the minute and possibly the second component of a custom date and time format string, along with any time separator symbols. The replacement pattern `HH${nonHours}` prepends the substring "HH" to these elements. @@ -384,9 +304,7 @@ The `nonHours` capturing group contains the minute and possibly the second compo The following example adds the "g" custom format specifier to the property of an object that represents the formatting conventions of the en-US culture. This addition affects the following three standard format strings: - The "D" (long date) standard format string, which maps directly to the property. - - The "f" (full date / short time) standard format string, which produces a result string that concatenates the substrings produced by the and properties. - - The "F" (full date / long time) standard format string, which maps directly to the property. Because we have not explicitly set this property value, it is generated dynamically by concatenating the and properties. The example also shows how to change the era name for a culture whose calendar has a single era. In this case, the en-US culture uses the Gregorian calendar, which is represented by a object. The class supports a single era, which it names A.D. (Anno Domini). The example changes the era name to C.E. (Common Era) by replacing the "g" custom format specifier in the format string assigned to the property with a literal string. The use of a literal string is necessary, because the era name is typically returned by the method from private data in the culture tables supplied by either .NET or the operating system. diff --git a/xml/System.Globalization/PersianCalendar.xml b/xml/System.Globalization/PersianCalendar.xml index f6bda4b88c3..eaac6fc3659 100644 --- a/xml/System.Globalization/PersianCalendar.xml +++ b/xml/System.Globalization/PersianCalendar.xml @@ -73,7 +73,7 @@ The Persian calendar is used in most countries/regions where Persian is spoken, > [!NOTE] > For information about using the class and the other calendar classes in .NET, see [Working with Calendars](/dotnet/standard/datetime/working-with-calendars). -The Persian calendar is a solar Hijri calendar, and starts from the year of the Hijra, which corresponds to 622 C.E. the year when Muhammad (PBUH) migrated from Mecca to Medina. +The Persian calendar is a solar Hijri calendar, and starts from the year of the Hijra, which corresponds to 622 C.E., which is the year when Muhammad migrated from Mecca to Medina. The Persian calendar is based on a solar year and is approximately 365 days long. A year cycles through four seasons, and a new year begins when the sun appears to cross the equator from the southern hemisphere to the northern hemisphere as viewed from the center of the Earth. The new year marks the first day of the month of Farvardeen, which is the first day of spring in the northern hemisphere. For example, the date March 21, 2002 C.E. corresponds to the first day of the month of Farvardeen in the year 1381 Anno Persico. diff --git a/xml/System.IO/FileSystemWatcher.xml b/xml/System.IO/FileSystemWatcher.xml index 3b8545d70d4..f4955fcb2da 100644 --- a/xml/System.IO/FileSystemWatcher.xml +++ b/xml/System.IO/FileSystemWatcher.xml @@ -70,7 +70,7 @@ Use to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. You can create a component to watch files on a local computer, a network drive, or a remote computer. -To watch for changes in all files, set the property to an empty string ("") or use wildcards ("*.\*"). To watch a specific file, set the property to the file name. For example, to watch for changes in the file MyDoc.txt, set the property to "MyDoc.txt". You can also watch for changes in a certain type of file. For example, to watch for changes in text files, set the property to "\*.txt". +To watch for changes in all files, set the property to an empty string (`""`) or use wildcards (`"*.*"`). To watch a specific file, set the property to the file name. For example, to watch for changes in the file MyDoc.txt, set the property to `"MyDoc.txt"`. You can also watch for changes in a certain type of file. For example, to watch for changes in text files, set the property to `"*.txt"`. There are several types of changes you can watch for in a directory or file. For example, you can watch for changes in `Attributes`, the `LastWrite` date and time, or the `Size` of files or directories. This is done by setting the property to one of the values. For more information on the type of changes you can watch, see . @@ -80,11 +80,10 @@ The Windows operating system notifies your component of file changes in a buffer For a list of initial property values for an instance of , see the constructor. -Considerations when using the class: +Consider the following facts when you use the class: -- Hidden files are not ignored. -- In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFil~.Lon". -- This class contains a link demand and an inheritance demand at the class level that applies to all members. A is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see [Link Demands](/dotnet/framework/misc/link-demands). +- Hidden files aren't ignored. +- In some systems, reports changes to files using the short 8.3 file name format. For example, a change to "LongFileName.LongExtension" could be reported as "LongFil~.Lon". - The maximum size you can set for the property for monitoring a directory over the network is 64 KB. ## Copy and move folders @@ -93,10 +92,10 @@ The operating system and object interpret a c To be notified that the contents of folders have been moved or copied into a watched folder, provide and event handler methods as suggested in the following table. -|Event Handler|Events Handled|Performs| -|-------------------|--------------------|--------------| -||, , |Report changes in file attributes, created files, and deleted files.| -|||List the old and new paths of renamed files and folders, expanding recursively if needed.| +| Event Handler | Events Handled | Performs | +|-----------------------------------------------|----------------|----------| +| | , , | Report changes in file attributes, created files, and deleted files. | +| | |List the old and new paths of renamed files and folders, expanding recursively if needed. | ## Events and buffer sizes From e2ec3099dfae0636688c02a7eecd46f2cd94b81e Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 5 Jun 2026 14:51:40 -0700 Subject: [PATCH 8/8] fix build errors --- xml/System.Globalization/CultureInfo.xml | 265 ++++++++---------- .../DateTimeFormatInfo.xml | 124 ++++---- 2 files changed, 181 insertions(+), 208 deletions(-) diff --git a/xml/System.Globalization/CultureInfo.xml b/xml/System.Globalization/CultureInfo.xml index d7f5b278b00..80035b007e6 100644 --- a/xml/System.Globalization/CultureInfo.xml +++ b/xml/System.Globalization/CultureInfo.xml @@ -83,7 +83,7 @@ ## Remarks - The class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the , , , and objects. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings. The class is used either directly or indirectly by classes that format, parse, or manipulate culture-specific data, such as , , , and the numeric types. +The class provides information associated with a specific culture, such as language, sublanguage, country/region, calendar, and conventions. This class also provides access to culture-specific instances of the , , , and objects. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings. The class is used either directly or indirectly by classes that format, parse, or manipulate culture-specific data, such as , , , and the numeric types. ## Culture names and identifiers @@ -139,11 +139,10 @@ On Windows, you can create custom locales. For more information, see [Custom loc ## CultureInfo and cultural data -.NET derives its cultural data from a one of a variety of sources, depending on implementation, platform, and version: +.NET derives its cultural data from two different sources, depending on the OS: -- In all versions of .NET (Core) running on Unix platforms or Windows 10 and later versions, cultural data is provided by the [International Components for Unicode (ICU) Library](https://icu.unicode.org/). The specific version of the ICU Library depends on the individual operating system. -- In all versions of .NET (Core) running on Windows 8.1 and earlier versions, cultural data is provided by the Windows operating system. -- In .NET Framework 4 and later versions, cultural data is provided by the Windows operating system. +- On Unix platforms or Windows 10 and later versions, cultural data is provided by the [International Components for Unicode (ICU) Library](https://icu.unicode.org/). The specific version of the ICU Library depends on the individual operating system. +- On Windows 8.1 and earlier versions, cultural data is provided by the Windows operating system. Because of this, a culture available on a particular .NET implementation, platform, or version may not be available on a different .NET implementation, platform, or version. @@ -194,9 +193,9 @@ The following example retrieves both property values, compares them to show that To change the culture and UI culture of a thread, do the following: -1. Instantiate a object that represents that culture by calling a class constructor and passing it the name of the culture. The constructor instantiates a object that reflects user overrides if the new culture is the same as the current Windows culture. The constructor allows you to specify whether the newly instantiated object reflects user overrides if the new culture is the same as the current Windows culture. +1. Instantiate a object that represents that culture by calling a class constructor and passing it the name of the culture. The constructor instantiates a object that reflects user overrides if the new culture is the same as the current Windows culture. The constructor allows you to specify whether the newly instantiated object reflects user overrides if the new culture is the same as the current Windows culture. -2. Assign the object to the or property on .NET Core and .NET Framework 4.6 and later versions. +2. Assign the object to the or property. The following example retrieves the current culture. If it is anything other than the French (France) culture, it changes the current culture to French (France). Otherwise, it changes the current culture to French (Luxembourg). @@ -230,7 +229,7 @@ When you assign values to the and objects to asynchronously execute delegates on thread pool threads. The specific thread on which a particular task runs is not known in advance, but is determined only at runtime. -For apps that target .NET Framework 4.6 or a later version, culture is part of an asynchronous operation's context. In other words, asynchronous operations by default inherit the values of the and properties of the thread from which they are launched. If the current culture or current UI culture differs from the system culture, the current culture crosses thread boundaries and becomes the current culture of the thread pool thread that is executing an asynchronous operation. +Culture is part of an asynchronous operation's context. In other words, asynchronous operations by default inherit the values of the and properties of the thread from which they are launched. If the current culture or current UI culture differs from the system culture, the current culture crosses thread boundaries and becomes the current culture of the thread pool thread that is executing an asynchronous operation. The following example provides a simple illustration. The example defines a delegate, `formatDelegate`, that returns some numbers formatted as currency values. The example changes the current system culture to either French (France) or, if French (France) is already the current culture, English (United States). It then: @@ -242,8 +241,6 @@ As the output from the example shows, when the current culture is changed to Fre :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/asyncculture1.cs" id="Snippet1"::: - and are per-app domain properties; that is, they establish a default culture for all threads not explicitly assigned a culture in a specific application domain. However, for apps that target .NET Framework 4.6 or later, the culture of the calling thread remains part of an asynchronous task's context even if the task crosses app domain boundaries. - ## CultureInfo object serialization When a object is serialized, all that is actually stored is and . It is successfully deserialized only in an environment where that has the same meaning. The following three examples show why this is not always the case: @@ -265,36 +262,30 @@ If is `true` and the sp Some cultures support more than one sort order. For example: - The Spanish (Spain) culture has two sort orders: the default international sort order, and the traditional sort order. When you instantiate a object with the `es-ES` culture name, the international sort order is used. When you instantiate a object with the `es-ES-tradnl` culture name, the traditional sort order is used. - - The `zh-CN` (Chinese (Simplified, PRC)) culture supports two sort orders: by pronunciation (the default) and by stroke count. When you instantiate a object with the `zh-CN` culture name, the default sort order is used. When you instantiate a object with a local identifier of 0x00020804, strings are sorted by stroke count. The following table lists the cultures that support alternate sort orders and the identifiers for the default and alternate sort orders. -|Culture name|Culture|Default sort name and identifier|Alternate sort name and identifier| -|------------------|-------------|--------------------------------------|----------------------------------------| -|es-ES|Spanish (Spain)|International: 0x00000C0A|Traditional: 0x0000040A| -|zh-TW|Chinese (Taiwan)|Stroke Count: 0x00000404|Bopomofo: 0x00030404| -|zh-CN|Chinese (PRC)|Pronunciation: 0x00000804|Stroke Count: 0x00020804| -|zh-HK|Chinese (Hong Kong SAR)|Stroke Count: 0x00000c04|Stroke Count: 0x00020c04| -|zh-SG|Chinese (Singapore)|Pronunciation: 0x00001004|Stroke Count: 0x00021004| -|zh-MO|Chinese (Macao SAR)|Pronunciation: 0x00001404|Stroke Count: 0x00021404| -|ja-JP|Japanese (Japan)|Default: 0x00000411|Unicode: 0x00010411| -|ko-KR|Korean (Korea)|Default: 0x00000412|Korean Xwansung - Unicode: 0x00010412| -|de-DE|German (Germany)|Dictionary: 0x00000407|Phone Book Sort DIN: 0x00010407| -|hu-HU|Hungarian (Hungary)|Default: 0x0000040e|Technical Sort: 0x0001040e| -|ka-GE|Georgian (Georgia)|Traditional: 0x00000437|Modern Sort: 0x00010437| - -## The current culture and UWP apps - -In Universal Windows Platform (UWP) apps, the and properties are read-write, just as they are in .NET Framework and .NET Core apps. However, UWP apps recognize a single culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. - -In .NET apps, the current culture is a per-thread setting, and the and properties reflect the culture and UI culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection, which is a global setting. Setting the or property changes the culture of the entire app; culture cannot be set on a per-thread basis. +| Culture name | Culture | Default sort name and identifier | Alternate sort name and identifier | +|--------------|-------------------------|----------------------------------|---------------------------------------| +| es-ES | Spanish (Spain) | International: 0x00000C0A | Traditional: 0x0000040A | +| zh-TW | Chinese (Taiwan) | Stroke Count: 0x00000404 | Bopomofo: 0x00030404 | +| zh-CN | Chinese (PRC) | Pronunciation: 0x00000804 | Stroke Count: 0x00020804 | +| zh-HK | Chinese (Hong Kong SAR) | Stroke Count: 0x00000c04 | Stroke Count: 0x00020c04 | +| zh-SG | Chinese (Singapore) | Pronunciation: 0x00001004 | Stroke Count: 0x00021004 | +| zh-MO | Chinese (Macao SAR) | Pronunciation: 0x00001404 | Stroke Count: 0x00021404 | +| ja-JP | Japanese (Japan) | Default: 0x00000411 | Unicode: 0x00010411 | +| ko-KR | Korean (Korea) | Default: 0x00000412 | Korean Xwansung - Unicode: 0x00010412 | +| de-DE | German (Germany) | Dictionary: 0x00000407 | Phone Book Sort DIN: 0x00010407 | +| hu-HU | Hungarian (Hungary) | Default: 0x0000040e | Technical Sort: 0x0001040e | +| ka-GE | Georgian (Georgia) | Traditional: 0x00000437 | Modern Sort: 0x00010437 | + ## Example - The following example shows how to create a object for Spanish (Spain) with the international sort and another object with the traditional sort. +The following example shows how to create a object for Spanish (Spain) with the international sort and another object with the traditional sort. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/spanishspain.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/Overview/spanishspain.vb" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/Overview/spanishspain.cs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/Overview/spanishspain.vb" id="Snippet1"::: ]]> @@ -1140,7 +1131,7 @@ When a thread is started, its culture is initially determined as follows: :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/Async1.cs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/Async1.vb" id="Snippet14"::: - For more information, see [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations). + For more information, see [Culture and task-based asynchronous operations](xref:System.Globalization.CultureInfo#culture-and-task-based-asynchronous-operations). - By calling the `GetUserDefaultLocaleName` function on Windows or the `uloc_getDefault` function from [ICU](https://icu-project.org/), which currently calls the POSIX `setlocale` function with category `LC_MESSAGES`, on Unix-like systems. @@ -1164,7 +1155,7 @@ To change the culture that's used by an existing thread, you set the [!NOTE] > Changing the culture by using the property requires a permission with the value set. Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code. -Starting with .NET Framework 4, you can explicitly change the current thread culture to either a specific culture (such as French (Canada)) or a neutral culture (such as French). When a object represents a neutral culture, the values of properties such as , , , , and reflect the specific culture that is associated with the neutral culture. For example, the dominant culture for the English neutral culture is English (United States); the dominant culture for the German culture is German (Germany). The following example illustrates the difference in formatting when the current culture is set to a specific culture, French (Canada), and a neutral culture, French. +You can explicitly change the current thread culture to either a specific culture (such as French (Canada)) or a neutral culture (such as French). When a object represents a neutral culture, the values of properties such as , , , , and reflect the specific culture that is associated with the neutral culture. For example, the dominant culture for the English neutral culture is English (United States); the dominant culture for the German culture is German (Germany). The following example illustrates the difference in formatting when the current culture is set to a specific culture, French (Canada), and a neutral culture, French. :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific12.cs" id="Snippet12"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentCulture/specific12.vb" id="Snippet12"::: @@ -1174,25 +1165,15 @@ Starting with .NET Framework 4, you can explicitly change the current thread cul Windows allows users to override the standard property values of the object and its associated objects by using **Regional and Language Options** in Control Panel. The object returned by the property reflects these user overrides in the following cases: - If the current thread culture is set implicitly by the Windows `GetUserDefaultLocaleName` function. - - If the current thread culture defined by the property corresponds to the current Windows system culture. - - If the current thread culture is set explicitly to a culture returned by the method, and that culture corresponds to the current Windows system culture. - - If the current thread culture is set explicitly to a culture instantiated by the constructor, and that culture corresponds to the current Windows system culture. In some cases, particularly for server applications, setting the current culture to a object that reflects user overrides may be undesirable. Instead, you can set the current culture to a object that does not reflect user overrides in the following ways: - By calling the constructor with a value of `false` for the `useUserOverride` argument. - - By calling the method, which returns a cached, read-only object. -## The current culture and UWP apps - -In Universal Windows Platform (UWP) apps, the property is read-write, just as it is in .NET Framework and .NET Core apps; you can use it both to get and to set the current culture. However, UWP apps do not distinguish between the current culture and the current UI culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. - -In .NET Framework and .NET Core apps, the current culture is a per-thread setting, and the property reflects the culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) property, which is a global setting. Setting the property changes the culture of the entire app; culture cannot be set on a per-thread basis. - ]]> @@ -1265,12 +1246,12 @@ The property is a per-t - By retrieving the culture that is specified by the property in the application domain in which the thread is executing, if the property value is not `null`. -- If the thread is a thread pool thread that is executing a task-based asynchronous operation and the app targets the .NET Framework 4.6 or a later version of the .NET Framework, its UI culture is determined by the UI culture of the calling thread. The following example changes the current UI culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current UI culture. Each of the tasks (and the threads) has inherited the UI culture of the calling thread. +- If the thread is a thread-pool thread that's executing a task-based asynchronous operation, its UI culture is determined by the UI culture of the calling thread. The following example changes the current UI culture to Portuguese (Brazil) and launches six tasks, each of which displays its thread ID, its task ID, and its current UI culture. Each of the tasks (and the threads) has inherited the UI culture of the calling thread. :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/Async1.cs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/Async1.vb" id="Snippet14"::: - For more information, see [Culture and task-based asynchronous operations](#culture-and-task-based-asynchronous-operations). + For more information, see [Culture and task-based asynchronous operations](xref:System.Globalization.CultureInfo#culture-and-task-based-asynchronous-operations). - By calling the Windows `GetUserDefaultUILanguage` function. @@ -1290,7 +1271,7 @@ You can also retrieve the value of the current thread's UI culture from the object that represents the new culture to the property. The current UI culture can be set to either a specific culture (such as en-US or de-DE) or to a neutral culture (such as en or de). The following example sets the current UI culture to fr-FR or French (France). +You can change the current UI culture by assigning a object that represents the new culture to the property. The current UI culture can be set to either a specific culture (such as en-US or de-DE) or to a neutral culture (such as en or de). The following example sets the current UI culture to fr-FR or French (France). :::code language="csharp" source="~/snippets/csharp/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.cs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/System.Globalization/CultureInfo/CurrentUICulture/currentuiculture1.vb" id="Snippet1"::: @@ -1315,12 +1296,6 @@ Changing the culture of the current thread requires a [!CAUTION] > Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code. -## The current UI culture and UWP apps - -In Universal Windows Platform (UWP) apps, the property is read-write, just as it is in .NET Framework and .NET Core apps; you can use it both to get and to set the current culture. However, UWP apps do not distinguish between the current culture and the current UI culture. The and properties map to the first value in the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) collection. - -In .NET Framework and .NET Core apps, the current UI culture is a per-thread setting, and the property reflects the UI culture of the current thread only. In UWP apps, the current culture maps to the [Windows.ApplicationModel.Resources.Core.ResourceManager.DefaultContext.Languages](/uwp/api/windows.applicationmodel.resources.core.resourcecontext#properties_) property, which is a global setting. Setting the property changes the culture of the entire app; culture cannot be set on a per-thread basis. - ]]> @@ -1894,97 +1869,95 @@ csc /resource:GreetingStrings.resources Example1.cs The user interface culture specifies the resources an application needs to support user input and output, and by default is the same as the operating system culture. For example, the property returns an Arabic culture for an Arabic operating system. Use the method to retrieve a culture suitable for a console application user interface. After your application retrieves the fallback user interface culture, it should assign the culture to the current user interface culture of the current thread. For more information, see the "Explicitly Setting the Current UI Culture" section of the property. - The following are predefined cultures that have a different fallback user interface culture name from the predefined culture name. - -|Predefined culture|Culture name|Fallback user interface culture name| -|------------------------|------------------|------------------------------------------| -|Amharic|am|en-US| -|Amharic (Ethiopia)|am-ET|en-US| -|(neutral Arabic)|ar|en-US| -|Arabic (U.A.E.)|ar-AE|en-US| -|Arabic (Bahrain)|ar-BH|en-US| -|Arabic (Algeria)|ar-DZ|fr-FR| -|Arabic (Egypt)|ar-EG|en-US| -|Arabic (Iraq)|ar-IQ|en-US| -|Arabic (Jordan)|ar-JO|en-US| -|Arabic (Kuwait)|ar-KW|en-US| -|Arabic (Lebanon)|ar-LB|en-US| -|Arabic (Libya)|ar-LY|en-US| -|Arabic (Morocco)|ar-MA|fr-FR| -|Arabic (Oman)|ar-OM|en-US| -|Arabic (Qatar)|ar-QA|en-US| -|Arabic (Saudi Arabia)|ar-SA|en-US| -|Arabic (Syria)|ar-SY|en-US| -|Arabic (Tunisia)|ar-TN|fr-FR| -|Arabic (Yemen)|ar-YE|en-US| -|Assamese|as|en-US| -|Assamese (India)|as-IN|en-US| -|Bangla|bn|en-US| -|Bangla (Bangladesh)|bn-BD|en-US| -|Bangla (India)|bn-IN|en-US| -|Tibetan|bo|en-US| -|Tibetan (PRC)|bo-CN|en-US| -|Divehi|dv|en-US| -|Divehi (India)|dv-MV|en-US| -|Persian|fa|en-US| -|Persian (Iran)|fa-IR|en-US| -|Gujarati|gu|en-US| -|Gujarati (India)|gu-IN|en-US| -|Hebrew|he|en-US| -|Hebrew (Israel)|he-IL|en-US| -|Hindi|hi|en-US| -|Hindi (India)|hi-IN|en-US| -|Yi|ii|en-US| -|Yi (PRC)|ii-CN|en-US| -|Inukitut Syllabics|iu-Cans|en-US| -|Inukitut Syllabics (Canada)|iu-Cans-CA|en-US| -|Khmer|km|en-US| -|Khmer (Cambodia)|km-KH|en-US| -|Kannada|kn|en-US| -|Kannada (India)|kn-IN|en-US| -|Konkani|kok|en-US| -|Konkani (India)|kok-IN|en-US| -|Lao|lo|en-US| -|Lao (Lao P.D.R.)|lo-LA|en-US| -|Malayalam|ml|en-US| -|Malayalam (India)|ml-IN|en-US| -|Mohawk|moh|en-US| -|Mohawk (Canada)|moh-CA|en-US| -|Marathi|mr|en-US| -|Marathi (India)|mr-IN|en-US| -|Nepali|ne|en-US| -|Nepali (Nepal)|ne-NP|en-US| -|Norwegian|no|nb-NO| -|Odiya|or|en-US| -|Odiya (India)|or-IN|en-US| -|Punjabi|pa|en-US| -|Punjabi (India)|pa-IN|en-US| -|Dari|prs|en-US| -|Dari (Afghanistan)|prs-AF|en-US| -|Pashto|ps|en-US| -|Pashto (Afghanistan)|ps-AF|en-US| -|Sanskrit|sa|en-US| -|Sanskrit (India)|sa-IN|en-US| -|Sinhala|si|en-US| -|Sinhala (Sri Lanka)|si-LK|en-US| -|Syriac|syr|en-US| -|Syriac (Syria)|syr-SY|en-US| -|Tamil|ta|en-US| -|Tamil (India)|ta-IN|en-US| -|Telugu|te|en-US| -|Telugu (India)|te-IN|en-US| -|Thai|th|en-US| -|Thai (Thailand)|th-Th|en-US| -|Uighur|ug|en-US| -|Uighur (PRC)|ug-CN|en-US| -|Urdu|ur|en-US| -|Urdu (Pakistan)|ur-PK|en-US| -|Vietnamese|vi|en-US| -|Vietnamese (Vietnam)|vi-VN|en-US| - - Your application can use to create a replacement for a culture, and that culture can have a console fallback culture of your choosing. - - + The following are predefined cultures that have a different fallback user-interface culture name from the predefined culture name. + +| Predefined culture | Culture name | Fallback user-interface culture name | +|-----------------------------|--------------|--------------------------------------| +| Amharic | am | en-US | +| Amharic (Ethiopia) | am-ET | en-US | +| (neutral Arabic) | ar | en-US | +| Arabic (U.A.E.) | ar-AE | en-US | +| Arabic (Bahrain) | ar-BH | en-US | +| Arabic (Algeria) | ar-DZ | fr-FR | +| Arabic (Egypt) | ar-EG | en-US | +| Arabic (Iraq) | ar-IQ | en-US | +| Arabic (Jordan) | ar-JO | en-US | +| Arabic (Kuwait) | ar-KW | en-US | +| Arabic (Lebanon) | ar-LB | en-US | +| Arabic (Libya) | ar-LY | en-US | +| Arabic (Morocco) | ar-MA | fr-FR | +| Arabic (Oman) | ar-OM | en-US | +| Arabic (Qatar) | ar-QA | en-US | +| Arabic (Saudi Arabia) | ar-SA | en-US | +| Arabic (Syria) | ar-SY | en-US | +| Arabic (Tunisia) | ar-TN | fr-FR | +| Arabic (Yemen) | ar-YE | en-US | +| Assamese | as | en-US | +| Assamese (India) | as-IN | en-US | +| Bangla | bn | en-US | +| Bangla (Bangladesh) | bn-BD | en-US | +| Bangla (India) | bn-IN | en-US | +| Tibetan | bo | en-US | +| Tibetan (PRC) | bo-CN | en-US | +| Divehi | dv | en-US | +| Divehi (India) | dv-MV | en-US | +| Persian | fa | en-US | +| Persian (Iran) | fa-IR | en-US | +| Gujarati | gu | en-US | +| Gujarati (India) | gu-IN | en-US | +| Hebrew | he | en-US | +| Hebrew (Israel) | he-IL | en-US | +| Hindi | hi | en-US | +| Hindi (India) | hi-IN | en-US | +| Yi | ii | en-US | +| Yi (PRC) | ii-CN | en-US | +| Inukitut Syllabics | iu-Cans | en-US | +| Inukitut Syllabics (Canada) | iu-Cans-CA | en-US | +| Khmer | km | en-US | +| Khmer (Cambodia) | km-KH | en-US | +| Kannada | kn | en-US | +| Kannada (India) | kn-IN | en-US | +| Konkani | kok | en-US | +| Konkani (India) | kok-IN | en-US | +| Lao | lo | en-US | +| Lao (Lao P.D.R.) | lo-LA | en-US | +| Malayalam | ml | en-US | +| Malayalam (India) | ml-IN | en-US | +| Mohawk | moh | en-US | +| Mohawk (Canada) | moh-CA | en-US | +| Marathi | mr | en-US | +| Marathi (India) | mr-IN | en-US | +| Nepali | ne | en-US | +| Nepali (Nepal) | ne-NP | en-US | +| Norwegian | no | nb-NO | +| Odiya | or | en-US | +| Odiya (India) | or-IN | en-US | +| Punjabi | pa | en-US | +| Punjabi (India) | pa-IN | en-US | +| Dari | prs | en-US | +| Dari (Afghanistan) | prs-AF | en-US | +| Pashto | ps | en-US | +| Pashto (Afghanistan) | ps-AF | en-US | +| Sanskrit | sa | en-US | +| Sanskrit (India) | sa-IN | en-US | +| Sinhala | si | en-US | +| Sinhala (Sri Lanka) | si-LK | en-US | +| Syriac | syr | en-US | +| Syriac (Syria) | syr-SY | en-US | +| Tamil | ta | en-US | +| Tamil (India) | ta-IN | en-US | +| Telugu | te | en-US | +| Telugu (India) | te-IN | en-US | +| Thai | th | en-US | +| Thai (Thailand) | th-Th | en-US | +| Uighur | ug | en-US | +| Uighur (PRC) | ug-CN | en-US | +| Urdu | ur | en-US | +| Urdu (Pakistan) | ur-PK | en-US | +| Vietnamese | vi | en-US | +| Vietnamese (Vietnam) | vi-VN | en-US | + +Your application can use to create a replacement for a culture, and that culture can have a console fallback culture of your choosing. ## Examples The following code example displays the fallback user interface culture associated with a culture object. @@ -2721,7 +2694,7 @@ Setting `predefinedOnly` to `true` will ensure a culture is created only if the The invariant culture is culture-insensitive; it's associated with the English language but not with any country/region. You specify the invariant culture by name by using an empty string ("") in the call to a instantiation method. This property, , also retrieves an instance of the invariant culture. It can be used in almost any method in the namespace that requires a culture. The objects returned by properties such as , , and also reflect the string comparison and formatting conventions of the invariant culture. -Unlike culture-sensitive data, which is subject to change by user customization or by updates to the .NET Framework or the operating system, invariant culture data is stable over time and across installed cultures and cannot be customized by users. This makes the invariant culture particularly useful for operations that require culture-independent results, such as formatting and parsing operations that persist formatted data, or sorting and ordering operations that require that data be displayed in a fixed order regardless of culture. +Unlike culture-sensitive data, which is subject to change by user customization or by updates to .NET or the operating system, invariant culture data is stable over time and across installed cultures and cannot be customized by users. This makes the invariant culture particularly useful for operations that require culture-independent results, such as formatting and parsing operations that persist formatted data, or sorting and ordering operations that require that data be displayed in a fixed order regardless of culture. ## String operations diff --git a/xml/System.Globalization/DateTimeFormatInfo.xml b/xml/System.Globalization/DateTimeFormatInfo.xml index b1604f80008..aedf9330b6d 100644 --- a/xml/System.Globalization/DateTimeFormatInfo.xml +++ b/xml/System.Globalization/DateTimeFormatInfo.xml @@ -359,8 +359,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par The following example uses reflection to get the properties of the object for the English (United States) culture. It displays the value of those properties that contain custom format strings and uses those strings to display formatted dates. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/Overview/format1.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/Overview/format1.vb" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/format1.cs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/format1.vb" id="Snippet5"::: ]]> @@ -478,8 +478,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated day names to its property. It then uses the "ddd" format specifier in a [custom date and time format string](/dotnet/standard/base-types/custom-date-and-time-format-strings) to display the string representation of dates for one week beginning May 28, 2014. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedDayNames/abbreviateddaynames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedDayNames/abbreviateddaynames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedDayNames/abbreviateddaynames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedDayNames/abbreviateddaynames1.vb" id="Snippet1"::: ]]> @@ -547,8 +547,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated genitive month names to its and properties. It then displays the string representation of dates that include the abbreviated month name of each month in the culture's supported calendar. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: ]]> @@ -619,8 +619,8 @@ It deserializes the data on a system in the Brussels, Copenhagen, Madrid and Par ## Examples The following example creates a read/write object that represents the English (United States) culture and assigns abbreviated genitive month names to its and properties. It then displays the string representation of dates that include the abbreviated name of each month in the culture's supported calendar. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/AbbreviatedMonthGenitiveNames/abbreviatedmonthnames1.vb" id="Snippet1"::: ]]> @@ -753,8 +753,8 @@ Changing the value of this property affects the following properties as well: object that represents the Arabic (Egypt) culture and first attempts to change its calendar to the Japanese calendar. Because the Japanese calendar is not supported, the method makes not change the culture's calendar. However, because the Umm al-Qura calendar is a member of the collection, the method does succeed in making it the current calendar for the ar-EG culture. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/Calendar/CalendarTest1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/Calendar/CalendarTest1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Calendar/CalendarTest1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Calendar/CalendarTest1.vb" id="Snippet1"::: ]]> @@ -937,8 +937,8 @@ Changing the value of this property affects the following properties as well: property to retrieve a object that represents the formatting conventions of the current culture, which in this case is the en-US culture. It then displays the format string and the result string for six formatting properties. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/CurrentInfo/CurrentInfo1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/CurrentInfo/CurrentInfo1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/CurrentInfo/CurrentInfo1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/CurrentInfo/CurrentInfo1.vb" id="Snippet1"::: ]]> @@ -998,8 +998,8 @@ Changing the value of this property affects the following properties as well: object for the en-US culture, changes its date separator to "-", and displays a date by using the "d", "G", and "g" standard format strings. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/DateSeparator/dateseparatorex.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/DateSeparator/dateseparatorex.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/DateSeparator/dateseparatorex.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/DateSeparator/dateseparatorex.vb" id="Snippet1"::: ]]> @@ -1192,8 +1192,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/FullDateTimePattern/dtfi_fulldatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/FullDateTimePattern/dtfi_fulldatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/FullDateTimePattern/dtfi_fulldatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/FullDateTimePattern/dtfi_fulldatetimepattern.vb" id="Snippet1"::: ]]> @@ -1493,8 +1493,8 @@ This property is affected if the value of the method in formatting operations. However, if you do, the string representation of a date and time value returned in that formatting operation cannot always be parsed successfully by the `Parse` and `TryParse` methods. Therefore, you cannot assume that the custom format strings returned by the method can be used to round-trip date and time values. The following example illustrates this problem. It retrieves a object that contains formatting information for the Italy (Italian) culture. It passes each custom format string in the array returned by the method to the method to create the string representation of a date and time. This example then attempts to parse this value by calling the method. As the output from the example shows, some of the custom format strings do not produce a date and time value that successfully round-trips. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex1.vb" id="Snippet1"::: To parse the string representation of a date and time that can be expressed in a number of predefined custom formats, call one of the following methods: @@ -1511,8 +1511,8 @@ This property is affected if the value of the object that represents the invariant culture by calling the constructor. It could also retrieve a that represents the invariant culture from the property. @@ -1575,8 +1575,8 @@ This property is affected if the value of the method in formatting operations. However, if you do, the string representation of a date and time value returned in that formatting operation cannot always be parsed successfully by the `Parse` and `TryParse` methods. Therefore, you cannot assume that the custom format strings returned by the method can be used to round-trip date and time values. The following example illustrates this problem. It retrieves a object that contains formatting information for the Russia (Russian) culture. It calls the method for each standard format string, and then passes each custom format string in the returned array to the method to create the string representation of a date and time. This example then attempts to parse this value by calling the method. As the output from the example shows, some of the custom format strings do not produce a date and time value that successfully round-trips. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex2.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetAllDateTimePatterns/getalldatetimepatternsex2.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex2.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetAllDateTimePatterns/getalldatetimepatternsex2.vb" id="Snippet2"::: To parse the string representation of a date and time that can be expressed in a number of predefined custom formats, call one of the following methods: @@ -1593,8 +1593,8 @@ This property is affected if the value of the @@ -1742,8 +1742,8 @@ This property is affected if the value of the ignores the punctuation in the era name, only if the calendar is Gregorian and the culture uses the era name "A.D.". - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetEra/gregorian_getera.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetEra/gregorian_getera.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetEra/gregorian_getera.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetEra/gregorian_getera.vb" id="Snippet1"::: ]]> @@ -2099,8 +2099,8 @@ This property is affected if the value of the @@ -2262,8 +2262,8 @@ This property is affected if the value of the property defines the culture-specific format of date strings that are returned by calls to the and methods and by composite format strings that are supplied the "D" standard format string. The following example illustrates the relationships among the following: the "D" standard format string, the custom format string returned by the property, and the culture-specific representation of a date. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern1.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern1.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern1.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern1.vb" id="Snippet2"::: See [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) for individual custom format specifiers that can be combined to construct custom format strings such as "dddd, dd MMMM yyyy". @@ -2271,14 +2271,14 @@ This property is affected if the value of the property of a object that represents the Arabic (Syria) culture changes when the object used by the culture changes. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern2.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/longdatepattern2.vb" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern2.cs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/longdatepattern2.vb" id="Snippet3"::: ## Examples The following example displays the value of the property for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/dtfi_longdatepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongDatePattern/dtfi_longdatepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongDatePattern/dtfi_longdatepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongDatePattern/dtfi_longdatepattern.vb" id="Snippet1"::: ]]> @@ -2343,8 +2343,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/LongTimePattern/dtfi_longtimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/LongTimePattern/dtfi_longtimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/LongTimePattern/dtfi_longtimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/LongTimePattern/dtfi_longtimepattern.vb" id="Snippet1"::: ]]> @@ -2411,8 +2411,8 @@ This property is affected if the value of the for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/MonthDayPattern/dtfi_monthdaypattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/MonthDayPattern/dtfi_monthdaypattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/MonthDayPattern/dtfi_monthdaypattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/MonthDayPattern/dtfi_monthdaypattern.vb" id="Snippet1"::: ]]> @@ -2476,8 +2476,8 @@ This property is affected if the value of the @@ -2602,8 +2602,8 @@ This property is affected if the value of the @@ -2789,8 +2789,8 @@ This property is affected if the value of the @@ -2860,8 +2860,8 @@ This property is affected if the value of the object that represents the "en-US" (English - United States) culture and uses it to parse an array of date and time strings using the "Y" standard format string. It then uses the method to associate a new custom format string with the "Y" standard format string, and then attempts to parse the array of date and time strings. Output from the example demonstrates that the new custom format string is used in both the parsing and formatting operations. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/SetAllDateTimePatterns/setalldatetimepatterns.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/SetAllDateTimePatterns/setalldatetimepatterns.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/SetAllDateTimePatterns/setalldatetimepatterns.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/SetAllDateTimePatterns/setalldatetimepatterns.vb" id="Snippet1"::: ]]> @@ -2934,13 +2934,13 @@ This property is affected if the value of the property and the value of a date formatted using the property for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/dtfi_shortdatepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/dtfi_shortdatepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortDatePattern/dtfi_shortdatepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortDatePattern/dtfi_shortdatepattern.vb" id="Snippet1"::: The following example modifies the property of a object that represents the formatting conventions of the English (United States) culture. It also displays a date value twice, first to reflect the original property and then to reflect the new property value. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/shortdatepattern1.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortDatePattern/shortdatepattern1.vb" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortDatePattern/shortdatepattern1.cs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortDatePattern/shortdatepattern1.vb" id="Snippet2"::: ]]> @@ -3003,8 +3003,8 @@ The default array starts on Sunday. ## Examples The following example demonstrates several methods and properties that specify date and time format patterns, native calendar name, and full and abbreviated month and day names. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/GetShortestDayName/dtfi1.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/GetShortestDayName/dtfi1.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/GetShortestDayName/dtfi1.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/GetShortestDayName/dtfi1.vb" id="Snippet1"::: ]]> @@ -3068,8 +3068,8 @@ The default array starts on Sunday. ## Examples The following example displays the value of for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/ShortTimePattern/dtfi_shorttimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/ShortTimePattern/dtfi_shorttimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/ShortTimePattern/dtfi_shorttimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/ShortTimePattern/dtfi_shorttimepattern.vb" id="Snippet1"::: ]]> @@ -3134,8 +3134,8 @@ The default array starts on Sunday. ## Examples The following example displays the value of for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/SortableDateTimePattern/dtfi_sortabledatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/SortableDateTimePattern/dtfi_sortabledatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/SortableDateTimePattern/dtfi_sortabledatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/SortableDateTimePattern/dtfi_sortabledatetimepattern.vb" id="Snippet1"::: ]]> @@ -3201,8 +3201,8 @@ If the custom pattern includes the format pattern ":", object for the en-US culture, changes its date separator to ".", and displays a date by using the "t", "T", "F", "f", "G", and "g" standard format strings. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/TimeSeparator/timeseparatorex.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/TimeSeparator/timeseparatorex.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/TimeSeparator/timeseparatorex.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/TimeSeparator/timeseparatorex.vb" id="Snippet1"::: ]]> @@ -3268,8 +3268,8 @@ If the custom pattern includes the format pattern ":", for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/UniversalSortableDateTimePattern/dtfi_universalsortabledatetimepattern.vb" id="Snippet1"::: ]]> @@ -3335,8 +3335,8 @@ If the custom pattern includes the format pattern ":", for a few cultures. - :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/Overview/YearMonthPattern/dtfi_yearmonthpattern.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/Overview/YearMonthPattern/dtfi_yearmonthpattern.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Globalization/DateTimeFormatInfo/YearMonthPattern/dtfi_yearmonthpattern.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/System.Globalization/DateTimeFormatInfo/YearMonthPattern/dtfi_yearmonthpattern.vb" id="Snippet1"::: ]]>