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:

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

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

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

11-
Console.WriteLine("It is raining: {0}",
12-
raining ? "Yes" : "No");
13-
Console.WriteLine("The bus is late: {0}",
14-
busLate ? "Yes" : "No");
11+
Console.WriteLine($"It is raining: {(raining ? "Yes" : "No")}");
12+
Console.WriteLine($"The bus is late: {(busLate ? "Yes" : "No")}");
1513
}
1614
}
1715
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System/Byte/Overview/csharp/bitwise1.cs

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

@@ -13,8 +13,7 @@ public static void Main()
1313
byte mask = 0xFE;
1414
foreach (string value in values) {
1515
Byte byteValue = Byte.Parse(value, NumberStyles.AllowHexSpecifier);
16-
Console.WriteLine("{0} And {1} = {2}", byteValue, mask,
17-
byteValue & mask);
16+
Console.WriteLine($"{byteValue} And {mask} = {byteValue & mask}");
1817
}
1918
}
2019
}

docs/fundamentals/runtime-libraries/snippets/System/Byte/Overview/csharp/bitwise2.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet2>
1+
// <Snippet2>
22
using System;
33
using System.Collections.Generic;
44
using System.Globalization;
@@ -20,12 +20,7 @@ public static void Main()
2020
foreach (ByteString strValue in values)
2121
{
2222
byte byteValue = Byte.Parse(strValue.Value, NumberStyles.AllowHexSpecifier);
23-
Console.WriteLine("{0} ({1}) And {2} ({3}) = {4} ({5})",
24-
strValue.Sign * byteValue,
25-
Convert.ToString(byteValue, 2),
26-
mask, Convert.ToString(mask, 2),
27-
(strValue.Sign & Math.Sign(mask)) * (byteValue & mask),
28-
Convert.ToString(byteValue & mask, 2));
23+
Console.WriteLine($"{strValue.Sign * byteValue} ({Convert.ToString(byteValue, 2)}) And {mask} ({Convert.ToString(mask, 2)}) = {(strValue.Sign & Math.Sign(mask)) * (byteValue & mask)} ({Convert.ToString(byteValue & mask, 2)})");
2924
}
3025
}
3126

docs/fundamentals/runtime-libraries/snippets/System/Byte/Overview/csharp/byteinstantiation1.cs

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

33
public class Example2
44
{
@@ -15,7 +15,7 @@ private static void InstantiateByAssignment()
1515
byte value1 = 64;
1616
byte value2 = 255;
1717
// </Snippet1>
18-
Console.WriteLine("{0} {1}", value1, value2);
18+
Console.WriteLine($"{value1} {value2}");
1919
}
2020

2121
private static void InstantiateByNarrowingConversion()
@@ -29,7 +29,7 @@ private static void InstantiateByNarrowingConversion()
2929
}
3030
catch (OverflowException)
3131
{
32-
Console.WriteLine("{0} is out of range of a byte.", int1);
32+
Console.WriteLine($"{int1} is out of range of a byte.");
3333
}
3434

3535
double dbl2 = 3.997;
@@ -40,7 +40,7 @@ private static void InstantiateByNarrowingConversion()
4040
}
4141
catch (OverflowException)
4242
{
43-
Console.WriteLine("{0} is out of range of a byte.", dbl2);
43+
Console.WriteLine($"{dbl2} is out of range of a byte.");
4444
}
4545
// The example displays the following output:
4646
// 128
@@ -59,11 +59,11 @@ private static void Parse()
5959
}
6060
catch (OverflowException)
6161
{
62-
Console.WriteLine("'{0}' is out of range of a byte.", string1);
62+
Console.WriteLine($"'{string1}' is out of range of a byte.");
6363
}
6464
catch (FormatException)
6565
{
66-
Console.WriteLine("'{0}' is out of range of a byte.", string1);
66+
Console.WriteLine($"'{string1}' is out of range of a byte.");
6767
}
6868

6969
string string2 = "F9";
@@ -75,11 +75,11 @@ private static void Parse()
7575
}
7676
catch (OverflowException)
7777
{
78-
Console.WriteLine("'{0}' is out of range of a byte.", string2);
78+
Console.WriteLine($"'{string2}' is out of range of a byte.");
7979
}
8080
catch (FormatException)
8181
{
82-
Console.WriteLine("'{0}' is out of range of a byte.", string2);
82+
Console.WriteLine($"'{string2}' is out of range of a byte.");
8383
}
8484
// The example displays the following output:
8585
// 244

0 commit comments

Comments
 (0)