Skip to content

Commit db28c8d

Browse files
authored
Fix the interactive errors on string.format. (#953)
contributes to dotnet/dotnet-api-docs#2539 When possible, update the snippets to work as included snippets. Otherwise, turn off the interactive samples on those samples.
1 parent 1cb65b2 commit db28c8d

File tree

16 files changed

+100
-95
lines changed

16 files changed

+100
-95
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// <Snippet4>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet4>
88
string formatString = " {0,10} ({0,8:X8})\n" +
99
"And {1,10} ({1,8:X8})\n" +
1010
" = {2,10} ({2,8:X8})";
@@ -13,10 +13,10 @@ public static void Main()
1313
string result = String.Format(formatString,
1414
value1, value2, value1 & value2);
1515
Console.WriteLine(result);
16+
// The example displays the following output:
17+
// 16932 (00004224)
18+
// And 15421 (00003C3D)
19+
// = 36 (00000024)
20+
// </Snippet4>
1621
}
1722
}
18-
// The example displays the following output:
19-
// 16932 (00004224)
20-
// And 15421 (00003C3D)
21-
// = 36 (00000024)
22-
// </Snippet4>
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// <Snippet5>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet5>
88
DateTime date1 = new DateTime(2009, 7, 1);
99
TimeSpan hiTime = new TimeSpan(14, 17, 32);
1010
decimal hiTemp = 62.1m;
@@ -19,13 +19,13 @@ public static void Main()
1919
string result2 = String.Format("Temperature on {0:d}:\n{1,11}: {2} degrees (hi)\n{3,11}: {4} degrees (lo)",
2020
new object[] { date1, hiTime, hiTemp, loTime, loTemp });
2121
Console.WriteLine(result2);
22+
// The example displays output like the following:
23+
// Temperature on 7/1/2009:
24+
// 14:17:32: 62.1 degrees (hi)
25+
// 03:16:10: 54.8 degrees (lo)
26+
// Temperature on 7/1/2009:
27+
// 14:17:32: 62.1 degrees (hi)
28+
// 03:16:10: 54.8 degrees (lo)
29+
// </Snippet5>
2230
}
2331
}
24-
// The example displays output like the following:
25-
// Temperature on 7/1/2009:
26-
// 14:17:32: 62.1 degrees (hi)
27-
// 03:16:10: 54.8 degrees (lo)
28-
// Temperature on 7/1/2009:
29-
// 14:17:32: 62.1 degrees (hi)
30-
// 03:16:10: 54.8 degrees (lo)
31-
// </Snippet5>

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/format7.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// <Snippet7>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet7>
88
DateTime birthdate = new DateTime(1993, 7, 28);
99
DateTime[] dates = { new DateTime(1993, 8, 16),
1010
new DateTime(1994, 7, 28),
@@ -28,12 +28,12 @@ public static void Main()
2828
Console.WriteLine(output);
2929
}
3030
}
31+
// The example displays the following output:
32+
// You are now 0 years old.
33+
// You are now 1 years old.
34+
// You are now 7 years old.
35+
// You are now 9 years old.
36+
// You are now 13 years old.
37+
// </Snippet7>
3138
}
3239
}
33-
// The example displays the following output:
34-
// You are now 0 years old.
35-
// You are now 1 years old.
36-
// You are now 7 years old.
37-
// You are now 9 years old.
38-
// You are now 13 years old.
39-
// </Snippet7>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// <Snippet6>
21
using System;
32
using System.Collections.Generic;
43

54
public class Example
65
{
76
public static void Main()
87
{
8+
// <Snippet6>
99
Dictionary<DateTime, Double> temperatureInfo = new Dictionary<DateTime, Double>();
1010
temperatureInfo.Add(new DateTime(2010, 6, 1, 14, 0, 0), 87.46);
1111
temperatureInfo.Add(new DateTime(2010, 12, 1, 10, 0, 0), 36.81);
@@ -18,11 +18,11 @@ public static void Main()
1818
item.Key, item.Value);
1919
Console.WriteLine(output);
2020
}
21+
// The example displays output like the following:
22+
// Temperature Information:
23+
//
24+
// Temperature at 2:00 PM on 6/1/2010: 87.5°F
25+
// Temperature at 10:00 AM on 12/1/2010: 36.8°F
26+
// </Snippet6>
2127
}
2228
}
23-
// The example displays output like the following:
24-
// Temperature Information:
25-
//
26-
// Temperature at 2:00 PM on 6/1/2010: 87.5°F
27-
// Temperature at 10:00 AM on 12/1/2010: 36.8°F
28-
// </Snippet6>

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/formatoverload2.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// <Snippet9>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet9>
88
// Create array of 5-tuples with population data for three U.S. cities, 1940-1950.
99
Tuple<string, DateTime, int, DateTime, int>[] cities =
1010
{ Tuple.Create("Los Angeles", new DateTime(1940, 1, 1), 1504277,
@@ -25,14 +25,14 @@ public static void Main()
2525
city.Item1, city.Item2, city.Item3, city.Item4, city.Item5,
2626
(city.Item5 - city.Item3)/ (double)city.Item3);
2727
Console.WriteLine(output);
28+
// The example displays the following output:
29+
// City Year Population Year Population Change (%)
30+
//
31+
// Los Angeles 1940 1,504,277 1950 1,970,358 31.0 %
32+
// New York 1940 7,454,995 1950 7,891,957 5.9 %
33+
// Chicago 1940 3,396,808 1950 3,620,962 6.6 %
34+
// Detroit 1940 1,623,452 1950 1,849,568 13.9 %
35+
// </Snippet9>
2836
}
2937
}
3038
}
31-
// The example displays the following output:
32-
// City Year Population Year Population Change (%)
33-
//
34-
// Los Angeles 1940 1,504,277 1950 1,970,358 31.0 %
35-
// New York 1940 7,454,995 1950 7,891,957 5.9 %
36-
// Chicago 1940 3,396,808 1950 3,620,962 6.6 %
37-
// Detroit 1940 1,623,452 1950 1,849,568 13.9 %
38-
// </Snippet9>

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/qa-interpolated1.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public class Example
44
{
55
public static void Main()
66
{
7+
// <SnippetQAInterpolated>
78
string[] names = { "Balto", "Vanya", "Dakota", "Samuel", "Koani", "Yiska", "Yuma" };
89
string output = names[0] + ", " + names[1] + ", " + names[2] + ", " +
910
names[3] + ", " + names[4] + ", " + names[5] + ", " +
@@ -14,9 +15,9 @@ public static void Main()
1415
output += String.Format("It is {0:t} on {0:d}. The day of the week is {1}.",
1516
date, date.DayOfWeek);
1617
Console.WriteLine(output);
18+
// The example displays the following output:
19+
// Balto, Vanya, Dakota, Samuel, Koani, Yiska, Yuma
20+
// It is 10:29 AM on 1/8/2018. The day of the week is Monday.
21+
// </SnippetQAInterpolated>
1722
}
1823
}
19-
// The example displays the following output:
20-
// Balto, Vanya, Dakota, Samuel, Koani, Yiska, Yuma
21-
// It is 10:29 AM on 1/8/2018. The day of the week is Monday.
22-

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/qa-interpolated2.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public class Example
44
{
5+
// <SnippetQAInterpolated2>
56
public static void Main()
67
{
78
string[] names = { "Balto", "Vanya", "Dakota", "Samuel", "Koani", "Yiska", "Yuma" };
@@ -11,9 +12,10 @@ public static void Main()
1112
var date = DateTime.Now;
1213
output += $"\nIt is {date:t} on {date:d}. The day of the week is {date.DayOfWeek}.";
1314
Console.WriteLine(output);
15+
// The example displays the following output:
16+
// Balto, Vanya, Dakota, Samuel, Koani, Yiska, Yuma
17+
// It is 10:29 AM on 1/8/2018. The day of the week is Monday.
18+
// </SnippetQAInterpolated2>
1419
}
1520
}
16-
// The example displays the following output:
17-
// Balto, Vanya, Dakota, Samuel, Koani, Yiska, Yuma
18-
// It is 10:29 AM on 1/8/2018. The day of the week is Monday.
1921

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/qa1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// <Snippet21>
21
using System;
32
using System.Collections.Generic;
43

54
public class Example
65
{
76
public static void Main()
87
{
8+
// <Snippet21>
99
Random rnd = new Random();
1010
int[] numbers = new int[4];
1111
int total = 0;
@@ -16,6 +16,6 @@ public static void Main()
1616
}
1717
numbers[3] = total;
1818
Console.WriteLine("{0} + {1} + {2} = {3}", numbers);
19+
// </Snippet21>
1920
}
2021
}
21-
// </Snippet21>

snippets/csharp/VS_Snippets_CLR_System/system.String.Format/cs/qa2.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// <Snippet22>
21
using System;
32
using System.Collections.Generic;
43

54
public class Example
65
{
76
public static void Main()
87
{
8+
// <Snippet22>
99
Random rnd = new Random();
1010
int[] numbers = new int[4];
1111
int total = 0;
@@ -18,6 +18,6 @@ public static void Main()
1818
object[] values = new object[numbers.Length];
1919
numbers.CopyTo(values, 0);
2020
Console.WriteLine("{0} + {1} + {2} = {3}", values);
21+
// </Snippet22>
2122
}
2223
}
23-
// </Snippet22>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// <Snippet26>
21
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet26>
88
object[] values = { 1603, 1794.68235, 15436.14 };
99
string result;
1010
foreach (var value in values) {
1111
result = String.Format("{0,12:C2} {0,12:E3} {0,12:F4} {0,12:N3} {1,12:P2}\n",
1212
Convert.ToDouble(value), Convert.ToDouble(value) / 10000);
1313
Console.WriteLine(result);
14+
// The example displays output like the following:
15+
// $1,603.00 1.603E+003 1603.0000 1,603.000 16.03 %
16+
//
17+
// $1,794.68 1.795E+003 1794.6824 1,794.682 17.95 %
18+
//
19+
// $15,436.14 1.544E+004 15436.1400 15,436.140 154.36 %
20+
// </Snippet26>
1421
}
1522
}
1623
}
17-
// The example displays output like the following:
18-
// $1,603.00 1.603E+003 1603.0000 1,603.000 16.03 %
19-
//
20-
// $1,794.68 1.795E+003 1794.6824 1,794.682 17.95 %
21-
//
22-
// $15,436.14 1.544E+004 15436.1400 15,436.140 154.36 %
23-
// </Snippet26>

0 commit comments

Comments
 (0)