Skip to content

Commit 21ad0a2

Browse files
authored
Update ToString4.cs
1 parent 130639c commit 21ad0a2

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

snippets/csharp/System/DateTime/ToString/ToString4.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
// <Snippet3>
2-
using System;
31
using System.Globalization;
42

53
public class ToStringExample3
64
{
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")};
5+
public static void Main()
6+
{
7+
// <Snippet3>
8+
CultureInfo[] cultures = [
9+
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")
15+
];
1516

16-
DateTime thisDate = new DateTime(2009, 5, 1, 9, 0, 0);
17+
DateTime thisDate = new(2025, 5, 1, 9, 0, 0);
1718

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;
19+
foreach (CultureInfo culture in cultures)
20+
{
21+
string cultureName;
22+
if (string.IsNullOrEmpty(culture.Name))
23+
cultureName = culture.NativeName;
24+
else
25+
cultureName = culture.Name;
2526

26-
Console.WriteLine("In {0}, {1}",
27-
cultureName, thisDate.ToString(culture));
28-
}
29-
}
27+
Console.WriteLine($"In {cultureName}, {thisDate.ToString(culture)}");
28+
}
29+
30+
// The example produces the following output:
31+
// In Invariant Language (Invariant Country), 05/01/2009 09:00:00
32+
// In en-US, 5/1/2009 9:00:00 AM
33+
// In fr-FR, 01/05/2009 09:00:00
34+
// In de-DE, 01.05.2009 09:00:00
35+
// In es-ES, 01/05/2009 9:00:00
36+
// In ja-JP, 2009/05/01 9:00:00
37+
// </Snippet3>
38+
}
3039
}
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

Comments
 (0)