Skip to content

Commit 62dd08e

Browse files
authored
Reinstate supplemental remarks (System.Globalization, System.IO) (#12705)
1 parent fc6656d commit 62dd08e

79 files changed

Lines changed: 3387 additions & 152 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// <Snippet14>
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
public class Example14
9+
{
10+
public static async Task Main()
11+
{
12+
var tasks = new List<Task>();
13+
Console.WriteLine($"The current culture is {Thread.CurrentThread.CurrentCulture.Name}");
14+
Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");
15+
// Change the current culture to Portuguese (Brazil).
16+
Console.WriteLine($"Current culture changed to {Thread.CurrentThread.CurrentCulture.Name}");
17+
Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}");
18+
// Launch six tasks and display their current culture.
19+
for (int ctr = 0; ctr <= 5; ctr++)
20+
tasks.Add(Task.Run(() =>
21+
{
22+
Console.WriteLine($"Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentCulture.Name}");
23+
}));
24+
25+
await Task.WhenAll(tasks.ToArray());
26+
}
27+
}
28+
29+
// The example displays output like the following:
30+
// The current culture is en-US
31+
// Current culture changed to pt-BR
32+
// Application thread is thread 9
33+
// Culture of task 2 on thread 11 is pt-BR
34+
// Culture of task 1 on thread 10 is pt-BR
35+
// Culture of task 3 on thread 11 is pt-BR
36+
// Culture of task 5 on thread 11 is pt-BR
37+
// Culture of task 6 on thread 11 is pt-BR
38+
// Culture of task 4 on thread 10 is pt-BR
39+
// </Snippet14>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// <Snippet5>
2+
using System;
3+
using System.Globalization;
4+
5+
public class Example5
6+
{
7+
public static void Main()
8+
{
9+
CultureInfo culture = CultureInfo.CurrentCulture;
10+
Console.WriteLine($"The current culture is {culture.NativeName} [{culture.Name}]");
11+
}
12+
}
13+
14+
// The example displays output like the following:
15+
// The current culture is English (United States) [en-US]
16+
// </Snippet5>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SetCultureExample.Run();

snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/aspculture1.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// <Snippet11>
2+
using System;
3+
using System.Globalization;
4+
using System.Threading;
5+
6+
public class Info11 : MarshalByRefObject
7+
{
8+
public void ShowCurrentCulture()
9+
{
10+
Console.WriteLine($"Culture of thread {Thread.CurrentThread.Name}: {CultureInfo.CurrentCulture.Name}");
11+
}
12+
}
13+
14+
public class SetCultureExample
15+
{
16+
public static void Run()
17+
{
18+
Info11 inf = new Info11();
19+
// Set the current culture to Dutch (Netherlands).
20+
Thread.CurrentThread.Name = "MainThread";
21+
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL");
22+
inf.ShowCurrentCulture();
23+
}
24+
}
25+
26+
// The example displays the following output:
27+
//
28+
// Culture of thread MainThread: nl-NL
29+
// </Snippet11>

snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// <snippet11>
22
using System;
33
using System.Globalization;
4-
using System.Threading;
54

65
public class Example0
76
{
@@ -22,6 +21,7 @@ public static void Main()
2221
Console.WriteLine("CurrentUICulture is now {0}.", CultureInfo.CurrentUICulture.Name);
2322
}
2423
}
24+
2525
// The example displays the following output:
2626
// CurrentCulture is en-US.
2727
// CurrentCulture is now th-TH.

snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/currentculture.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net4.8</TargetFramework>
6-
<StartupObject>Example5</StartupObject>
5+
<TargetFramework>net10.0</TargetFramework>
76
</PropertyGroup>
87

98
</Project>

snippets/csharp/System.Globalization/CultureInfo/CurrentCulture/specific1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void Main()
1919
Console.WriteLine("{0:C2}", value);
2020
}
2121
}
22+
2223
// The example displays the following output:
2324
// Current Culture: fr-CA
2425
// 1 634,92 $
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// <Snippet12>
2+
using System;
3+
using System.Globalization;
4+
using System.Threading;
5+
6+
public class Example12
7+
{
8+
public static void Main()
9+
{
10+
double value = 1634.92;
11+
CultureInfo.CurrentCulture = new CultureInfo("fr-CA");
12+
Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}");
13+
Console.WriteLine($"{value:C2}\n");
14+
15+
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
16+
Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}");
17+
Console.WriteLine($"{value:C2}");
18+
}
19+
}
20+
21+
// The example displays the following output:
22+
// Current Culture: fr-CA
23+
// 1 634,92 $
24+
//
25+
// Current Culture: fr
26+
// 1 634,92 €
27+
// </Snippet12>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// <Snippet14>
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Runtime.Versioning;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
public class Example
10+
{
11+
public static async Task Main()
12+
{
13+
var tasks = new List<Task>();
14+
Console.WriteLine($"The current UI culture is {Thread.CurrentThread.CurrentUICulture.Name}");
15+
Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR");
16+
// Change the current UI culture to Portuguese (Brazil).
17+
Console.WriteLine($"Current UI culture changed to {Thread.CurrentThread.CurrentUICulture.Name}");
18+
Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}");
19+
// Launch six tasks and display their current culture.
20+
for (int ctr = 0; ctr <= 5; ctr++)
21+
tasks.Add(Task.Run(() =>
22+
{
23+
Console.WriteLine($"UI Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentUICulture.Name}");
24+
}));
25+
26+
await Task.WhenAll(tasks.ToArray());
27+
}
28+
}
29+
30+
// The example displays output like the following:
31+
// The current UI culture is en-US
32+
// Current UI culture changed to pt-BR
33+
// Application thread is thread 9
34+
// UI Culture of task 2 on thread 11 is pt-BR
35+
// UI Culture of task 1 on thread 10 is pt-BR
36+
// UI Culture of task 3 on thread 11 is pt-BR
37+
// UI Culture of task 5 on thread 11 is pt-BR
38+
// UI Culture of task 6 on thread 11 is pt-BR
39+
// UI Culture of task 4 on thread 10 is pt-BR
40+
// </Snippet14>

0 commit comments

Comments
 (0)