|
1 |
| -// <Snippet3> |
2 |
| -using System; |
| 1 | +using System; |
3 | 2 | using System.Globalization;
|
4 | 3 |
|
5 | 4 | public class ToStringExample3
|
6 | 5 | {
|
7 |
| - public static void Main2() |
8 |
| - { |
9 |
| - CultureInfo[] cultures = new CultureInfo[] {CultureInfo.InvariantCulture, |
10 |
| - new CultureInfo("en-us"), |
11 |
| - new CultureInfo("fr-fr"), |
12 |
| - new CultureInfo("de-DE"), |
13 |
| - new CultureInfo("es-ES"), |
14 |
| - new CultureInfo("ja-JP")}; |
| 6 | + public static void Main() |
| 7 | + { |
| 8 | + // <Snippet3> |
| 9 | + CultureInfo[] cultures = [ |
| 10 | + CultureInfo.InvariantCulture, |
| 11 | + new CultureInfo("en-us"), |
| 12 | + new CultureInfo("fr-fr"), |
| 13 | + new CultureInfo("de-DE"), |
| 14 | + new CultureInfo("es-ES"), |
| 15 | + new CultureInfo("ja-JP") |
| 16 | + ]; |
15 | 17 |
|
16 |
| - DateTime thisDate = new DateTime(2009, 5, 1, 9, 0, 0); |
| 18 | + DateTime thisDate = new(2025, 5, 1, 9, 0, 0); |
17 | 19 |
|
18 |
| - foreach (CultureInfo culture in cultures) |
19 |
| - { |
20 |
| - string cultureName; |
21 |
| - if (string.IsNullOrEmpty(culture.Name)) |
22 |
| - cultureName = culture.NativeName; |
23 |
| - else |
24 |
| - cultureName = culture.Name; |
| 20 | + foreach (CultureInfo culture in cultures) |
| 21 | + { |
| 22 | + string cultureName; |
| 23 | + if (string.IsNullOrEmpty(culture.Name)) |
| 24 | + cultureName = culture.NativeName; |
| 25 | + else |
| 26 | + cultureName = culture.Name; |
25 | 27 |
|
26 |
| - Console.WriteLine("In {0}, {1}", |
27 |
| - cultureName, thisDate.ToString(culture)); |
28 |
| - } |
29 |
| - } |
| 28 | + Console.WriteLine($"In {cultureName}, {thisDate.ToString(culture)}"); |
| 29 | + } |
| 30 | + |
| 31 | + // The example produces the following output: |
| 32 | + // In Invariant Language (Invariant Country), 05/01/2009 09:00:00 |
| 33 | + // In en-US, 5/1/2009 9:00:00 AM |
| 34 | + // In fr-FR, 01/05/2009 09:00:00 |
| 35 | + // In de-DE, 01.05.2009 09:00:00 |
| 36 | + // In es-ES, 01/05/2009 9:00:00 |
| 37 | + // In ja-JP, 2009/05/01 9:00:00 |
| 38 | + // </Snippet3> |
| 39 | + } |
30 | 40 | }
|
31 |
| -// The example produces the following output: |
32 |
| -// In Invariant Language (Invariant Country), 05/01/2009 09:00:00 |
33 |
| -// In en-US, 5/1/2009 9:00:00 AM |
34 |
| -// In fr-FR, 01/05/2009 09:00:00 |
35 |
| -// In de-DE, 01.05.2009 09:00:00 |
36 |
| -// In es-ES, 01/05/2009 9:00:00 |
37 |
| -// In ja-JP, 2009/05/01 9:00:00 |
38 |
| -// </Snippet3> |
|
0 commit comments