Skip to content

Commit 2a216fb

Browse files
authored
Fix bad string interpolations (#45807)
* Fix bad string interpolations * Simplify the f specifier example
1 parent 4396866 commit 2a216fb

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

samples/snippets/csharp/VS_Snippets_CLR/conceptual.timespan.custom/cs/customexamples1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ private static void ddSpecifier()
6464
for (int ctr = 2; ctr <= 8; ctr++)
6565
{
6666
string fmt = new String('d', ctr) + @"\.hh\:mm\:ss";
67-
Console.WriteLine($"{fmt} --> {ts1:" + fmt + "}");
68-
Console.WriteLine($"{fmt} --> {ts2:" + fmt + "}");
67+
Console.WriteLine($"{fmt} --> {ts1.ToString(fmt)}");
68+
Console.WriteLine($"{fmt} --> {ts2.ToString(fmt)}");
6969
Console.WriteLine();
7070
}
7171
// The example displays the following output:

samples/snippets/csharp/VS_Snippets_CLR/conceptual.timespan.custom/cs/fspecifiers1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
public class Example
44
{
@@ -11,15 +11,15 @@ public static void Main()
1111
Console.WriteLine();
1212

1313
for (int ctr = 1; ctr <= 7; ctr++) {
14-
fmt = new String('f', ctr);
14+
fmt = new string('f', ctr);
1515
if (fmt.Length == 1) fmt = "%" + fmt;
16-
Console.WriteLine("{0,10}: {1:" + fmt + "}", fmt, ts);
16+
Console.WriteLine($"{fmt,10}: {ts.ToString(fmt)}");
1717
}
1818
Console.WriteLine();
1919

2020
for (int ctr = 1; ctr <= 7; ctr++) {
21-
fmt = new String('f', ctr);
22-
Console.WriteLine("{0,10}: {1:s\\." + fmt + "}", "s\\." + fmt, ts);
21+
fmt = $"s\\.{new string('f', ctr)}";
22+
Console.WriteLine($"{fmt,10}: {ts.ToString(fmt)}");
2323
}
2424
// The example displays the following output:
2525
// %f: 8

samples/snippets/csharp/VS_Snippets_CLR/conceptual.timespan.custom/cs/negativevalues1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public static void Main()
99
String fmt = (result < TimeSpan.Zero ? "\\-" : "") + "dd\\.hh\\:mm";
1010

1111
Console.WriteLine(result.ToString(fmt));
12-
Console.WriteLine($"Interval: {result:" + fmt + "}");
12+
Console.WriteLine($"Interval: {result.ToString(fmt)}");
1313
}
1414
}
1515
// The example displays output like the following:
16-
// -1291.10:54
17-
// Interval: -1291.10:54
16+
// -5582.12:21
17+
// Interval: -5582.12:21
1818
// </Snippet29>

0 commit comments

Comments
 (0)