Skip to content

Commit 851a2e0

Browse files
authored
use interpolated strings (#45453)
1 parent c1aa305 commit 851a2e0

File tree

139 files changed

+751
-1013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+751
-1013
lines changed

docs/fundamentals/runtime-libraries/snippets/System/AppContext/Overview/csharp/V1/Example4.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet4>
1+
// <Snippet4>
22
using System;
33
using System.Reflection;
44

@@ -26,10 +26,9 @@ public static void Main()
2626
string substring = "archæ";
2727
int position = StringLibrary1.SubstringStartsAt(value, substring);
2828
if (position >= 0)
29-
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
30-
substring, value, position);
29+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
3130
else
32-
Console.WriteLine("'{0}' not found in '{1}'", substring, value);
31+
Console.WriteLine($"'{substring}' not found in '{value}'");
3332
}
3433
}
3534
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System/AppContext/Overview/csharp/V2/Example6.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet6>
1+
// <Snippet6>
22
using System;
33
using System.Reflection;
44

@@ -26,10 +26,9 @@ public static void Main()
2626
string substring = "archæ";
2727
int position = StringLibrary2.SubstringStartsAt(value, substring);
2828
if (position >= 0)
29-
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
30-
substring, value, position);
29+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
3130
else
32-
Console.WriteLine("'{0}' not found in '{1}'", substring, value);
31+
Console.WriteLine($"'{substring}' not found in '{value}'");
3332
}
3433
}
3534
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System/AppContext/Overview/csharp/V3/Example8.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public static void Main()
3030
string substring = "archæ";
3131
int position = StringLibrary.SubstringStartsAt(value, substring);
3232
if (position >= 0)
33-
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
34-
substring, value, position);
33+
Console.WriteLine($"'{substring}' found in '{value}' starting at position {position}");
3534
else
36-
Console.WriteLine("'{0}' not found in '{1}'", substring, value);
35+
Console.WriteLine($"'{substring}' not found in '{value}'");
3736
}
3837
}
3938
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/binary1.cs

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

44
public class Example1
@@ -10,12 +10,11 @@ public static void Main()
1010
{
1111
// Get binary representation of flag.
1212
Byte value = BitConverter.GetBytes(flag)[0];
13-
Console.WriteLine("Original value: {0}", flag);
14-
Console.WriteLine("Binary value: {0} ({1})", value,
15-
GetBinaryString(value));
13+
Console.WriteLine($"Original value: {flag}");
14+
Console.WriteLine($"Binary value: {value} ({GetBinaryString(value)})");
1615
// Restore the flag from its binary representation.
1716
bool newFlag = BitConverter.ToBoolean(new Byte[] { value }, 0);
18-
Console.WriteLine("Restored value: {0}\n", flag);
17+
Console.WriteLine($"Restored value: {flag}{Environment.NewLine}");
1918
}
2019
}
2120

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/conversion3.cs

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

44
public class Example3
@@ -9,19 +9,19 @@ public static void Main()
99

1010
byte byteValue;
1111
byteValue = Convert.ToByte(flag);
12-
Console.WriteLine("{0} -> {1}", flag, byteValue);
12+
Console.WriteLine($"{flag} -> {byteValue}");
1313

1414
sbyte sbyteValue;
1515
sbyteValue = Convert.ToSByte(flag);
16-
Console.WriteLine("{0} -> {1}", flag, sbyteValue);
16+
Console.WriteLine($"{flag} -> {sbyteValue}");
1717

1818
double dblValue;
1919
dblValue = Convert.ToDouble(flag);
20-
Console.WriteLine("{0} -> {1}", flag, dblValue);
20+
Console.WriteLine($"{flag} -> {dblValue}");
2121

2222
int intValue;
2323
intValue = Convert.ToInt32(flag);
24-
Console.WriteLine("{0} -> {1}", flag, intValue);
24+
Console.WriteLine($"{flag} -> {intValue}");
2525
}
2626
}
2727
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/operations2.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet13>
1+
// <Snippet13>
22
using System;
33

44
public class Example6
@@ -13,8 +13,7 @@ public static void Main()
1313
foreach (var hasServiceCharge in hasServiceCharges) {
1414
Decimal total = subtotal + shippingCharge +
1515
(hasServiceCharge ? serviceCharge : 0);
16-
Console.WriteLine("hasServiceCharge = {1}: The total is {0:C2}.",
17-
total, hasServiceCharge);
16+
Console.WriteLine($"hasServiceCharge = {hasServiceCharge}: The total is {total:C2}.");
1817
}
1918
}
2019
}

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/parse2.cs

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

44
public class Example7
@@ -13,23 +13,23 @@ public static void Main()
1313
foreach (var value in values) {
1414
try {
1515
bool flag = Boolean.Parse(value);
16-
Console.WriteLine("'{0}' --> {1}", value, flag);
16+
Console.WriteLine($"'{value}' --> {flag}");
1717
}
1818
catch (ArgumentException) {
1919
Console.WriteLine("Cannot parse a null string.");
2020
}
2121
catch (FormatException) {
22-
Console.WriteLine("Cannot parse '{0}'.", value);
22+
Console.WriteLine($"Cannot parse '{value}'.");
2323
}
2424
}
2525
Console.WriteLine();
2626
// Parse strings using the Boolean.TryParse method.
2727
foreach (var value in values) {
2828
bool flag = false;
2929
if (Boolean.TryParse(value, out flag))
30-
Console.WriteLine("'{0}' --> {1}", value, flag);
30+
Console.WriteLine($"'{value}' --> {flag}");
3131
else
32-
Console.WriteLine("Unable to parse '{0}'", value);
32+
Console.WriteLine($"Unable to parse '{value}'");
3333
}
3434
}
3535
}

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/parse3.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet9>
1+
// <Snippet9>
22
using System;
33

44
public class Example8
@@ -13,10 +13,10 @@ public static void Main()
1313
if (success) {
1414
// The method throws no exceptions.
1515
result = Convert.ToBoolean(number);
16-
Console.WriteLine("Converted '{0}' to {1}", value, result);
16+
Console.WriteLine($"Converted '{value}' to {result}");
1717
}
1818
else {
19-
Console.WriteLine("Unable to convert '{0}'", value);
19+
Console.WriteLine($"Unable to convert '{value}'");
2020
}
2121
}
2222
}

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/size1.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet14>
1+
// <Snippet14>
22
using System;
33

44
public struct BoolStruct
@@ -17,13 +17,13 @@ public static void Main()
1717
unsafe {
1818
BoolStruct b = new BoolStruct();
1919
bool* addr = (bool*) &b;
20-
Console.WriteLine("Size of BoolStruct: {0}", sizeof(BoolStruct));
20+
Console.WriteLine($"Size of BoolStruct: {sizeof(BoolStruct)}");
2121
Console.WriteLine("Field offsets:");
22-
Console.WriteLine(" flag1: {0}", (bool*) &b.flag1 - addr);
23-
Console.WriteLine(" flag1: {0}", (bool*) &b.flag2 - addr);
24-
Console.WriteLine(" flag1: {0}", (bool*) &b.flag3 - addr);
25-
Console.WriteLine(" flag1: {0}", (bool*) &b.flag4 - addr);
26-
Console.WriteLine(" flag1: {0}", (bool*) &b.flag5 - addr);
22+
Console.WriteLine($" flag1: {(bool*) &b.flag1 - addr}");
23+
Console.WriteLine($" flag1: {(bool*) &b.flag2 - addr}");
24+
Console.WriteLine($" flag1: {(bool*) &b.flag3 - addr}");
25+
Console.WriteLine($" flag1: {(bool*) &b.flag4 - addr}");
26+
Console.WriteLine($" flag1: {(bool*) &b.flag5 - addr}");
2727
}
2828
}
2929
}

docs/fundamentals/runtime-libraries/snippets/System/Boolean/Overview/csharp/tostring1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet3>
1+
// <Snippet3>
22
using System;
33

44
public class Example10
@@ -8,8 +8,8 @@ public static void Main()
88
bool raining = false;
99
bool busLate = true;
1010

11-
Console.WriteLine("It is raining: {0}", raining);
12-
Console.WriteLine("The bus is late: {0}", busLate);
11+
Console.WriteLine($"It is raining: {raining}");
12+
Console.WriteLine($"The bus is late: {busLate}");
1313
}
1414
}
1515
// The example displays the following output:

0 commit comments

Comments
 (0)