Skip to content

Commit c6a8e29

Browse files
authored
Convert to interpolated strings (csharp dir) (#45441)
1 parent d3cae42 commit c6a8e29

File tree

27 files changed

+76
-77
lines changed

27 files changed

+76
-77
lines changed

docs/csharp/advanced-topics/expression-trees/snippets/InterpretExpressions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq.Expressions;
1+
using System.Linq.Expressions;
22
public static class InterpretExpressions
33
{
44
public static void ParseExpression()
@@ -16,8 +16,7 @@ public static void ParseExpression()
1616
ParameterExpression left = (ParameterExpression)operation.Left;
1717
ConstantExpression right = (ConstantExpression)operation.Right;
1818

19-
Console.WriteLine("Decomposed expression: {0} => {1} {2} {3}",
20-
param.Name, left.Name, operation.NodeType, right.Value);
19+
Console.WriteLine($"Decomposed expression: {param.Name} => {left.Name} {operation.NodeType} {right.Value}");
2120

2221
// This code produces the following output:
2322

docs/csharp/advanced-topics/reflection-and-attributes/snippets/conceptual/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
1+
// See https://aka.ms/new-console-template for more information
22

33

44
using System.Reflection;
@@ -35,10 +35,10 @@ from method in type.GetMethods()
3535

3636
foreach (var groupOfMethods in pubTypesQuery)
3737
{
38-
Console.WriteLine("Type: {0}", groupOfMethods.Key);
38+
Console.WriteLine($"Type: {groupOfMethods.Key}");
3939
foreach (var method in groupOfMethods)
4040
{
41-
Console.WriteLine(" {0}", method);
41+
Console.WriteLine($" {method}");
4242
}
4343
}
4444
// </QueryReflection>

docs/csharp/asynchronous-programming/snippets/async-scenarios/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.RegularExpressions;
1+
using System.Text.RegularExpressions;
22
using System.Windows;
33
using Microsoft.AspNetCore.Mvc;
44

@@ -111,7 +111,7 @@ private static void Download(string URL)
111111

112112
private static void DoSomethingWithData(object stringData)
113113
{
114-
Console.WriteLine("Displaying data: ", stringData);
114+
Console.WriteLine($"Displaying data: {stringData}");
115115
}
116116

117117
// <GetUsersForDataset>

docs/csharp/fundamentals/coding-style/snippets/coding-conventions/program.cs

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

33
namespace Coding_Conventions_Examples
44
{
@@ -32,7 +32,7 @@ public static void DelegateExamples()
3232

3333
public static void DelMethod(string str)
3434
{
35-
Console.WriteLine("DelMethod argument: {0}", str);
35+
Console.WriteLine($"DelMethod argument: {str}");
3636
}
3737
//</snippet14b>
3838

@@ -174,7 +174,7 @@ static void Main(string[] args)
174174

175175
if ((divisor != 0) && (dividend / divisor) is var result)
176176
{
177-
Console.WriteLine("Quotient: {0}", result);
177+
Console.WriteLine($"Quotient: {result}");
178178
}
179179
else
180180
{

docs/csharp/fundamentals/exceptions/snippets/exceptions/ExceptionTest.cs

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

33
namespace Exceptions
44
{
@@ -22,7 +22,7 @@ public static void Main()
2222
try
2323
{
2424
result = SafeDivision(a, b);
25-
Console.WriteLine("{0} divided by {1} = {2}", a, b, result);
25+
Console.WriteLine($"{a} divided by {b} = {result}");
2626
}
2727
catch (DivideByZeroException)
2828
{

docs/csharp/fundamentals/object-oriented/snippets/objects/Application.cs

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

33
namespace Example
44
{
@@ -20,7 +20,7 @@ static void Main()
2020
// Create struct instance and initialize by using "new".
2121
// Memory is allocated on thread stack.
2222
Person p1 = new Person("Alex", 9);
23-
Console.WriteLine("p1 Name = {0} Age = {1}", p1.Name, p1.Age);
23+
Console.WriteLine($"p1 Name = {p1.Name} Age = {p1.Age}");
2424

2525
// Create new struct object. Note that struct can be initialized
2626
// without using "new".
@@ -29,10 +29,10 @@ static void Main()
2929
// Assign values to p2 members.
3030
p2.Name = "Spencer";
3131
p2.Age = 7;
32-
Console.WriteLine("p2 Name = {0} Age = {1}", p2.Name, p2.Age);
32+
Console.WriteLine($"p2 Name = {p2.Name} Age = {p2.Age}");
3333

3434
// p1 values remain unchanged because p2 is copy.
35-
Console.WriteLine("p1 Name = {0} Age = {1}", p1.Name, p1.Age);
35+
Console.WriteLine($"p1 Name = {p1.Name} Age = {p1.Age}");
3636
}
3737
}
3838
/*

docs/csharp/fundamentals/object-oriented/snippets/objects/Program.cs

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

33
public class Person
44
{
@@ -17,7 +17,7 @@ class Program
1717
static void Main()
1818
{
1919
Person person1 = new Person("Leopold", 6);
20-
Console.WriteLine("person1 Name = {0} Age = {1}", person1.Name, person1.Age);
20+
Console.WriteLine($"person1 Name = {person1.Name} Age = {person1.Age}");
2121

2222
// Declare new person, assign person1 to it.
2323
Person person2 = person1;
@@ -26,8 +26,8 @@ static void Main()
2626
person2.Name = "Molly";
2727
person2.Age = 16;
2828

29-
Console.WriteLine("person2 Name = {0} Age = {1}", person2.Name, person2.Age);
30-
Console.WriteLine("person1 Name = {0} Age = {1}", person1.Name, person1.Age);
29+
Console.WriteLine($"person2 Name = {person2.Name} Age = {person2.Age}");
30+
Console.WriteLine($"person1 Name = {person1.Name} Age = {person1.Age}");
3131
}
3232
}
3333
/*

docs/csharp/language-reference/keywords/snippets/ParameterModifiers.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Keywords;
1+
namespace Keywords;
22

33
internal class ParameterModifiers
44
{
@@ -9,17 +9,17 @@ internal static void ParamPassingExamples()
99
// Passing a variable by value means passing a copy of the variable.
1010
// n1 is a value type
1111
int n1 = 5;
12-
System.Console.WriteLine("The value before calling the method: {0}", n1);
12+
System.Console.WriteLine($"The value before calling the method: {n1}");
1313

1414
SquareItValue(n1); // Passing the variable by value.
15-
System.Console.WriteLine("The value after calling the method: {0}", n1);
15+
System.Console.WriteLine($"The value after calling the method: {n1}");
1616

1717
static void SquareItValue(int x)
1818
// The parameter x is passed by value.
1919
// Changes to x will not affect the original value of x.
2020
{
2121
x *= x;
22-
System.Console.WriteLine("The value inside the method: {0}", x);
22+
System.Console.WriteLine($"The value inside the method: {x}");
2323
}
2424
/* Output:
2525
The value before calling the method: 5
@@ -49,17 +49,17 @@ static void ChangeValue(int[] pArray)
4949
// Passing a value by reference means passing a reference to the variable.
5050
// n is a value type
5151
int n2 = 5;
52-
System.Console.WriteLine("The value before calling the method: {0}", n2);
52+
System.Console.WriteLine($"The value before calling the method: {n2}");
5353

5454
SquareItReference(ref n2); // Passing the variable by reference.
55-
System.Console.WriteLine("The value after calling the method: {0}", n2);
55+
System.Console.WriteLine($"The value after calling the method: {n2}");
5656

5757
static void SquareItReference(ref int x)
5858
// The parameter x is passed by reference.
5959
// Changes to x will affect the original value of x.
6060
{
6161
x *= x;
62-
System.Console.WriteLine("The value inside the method: {0}", x);
62+
System.Console.WriteLine($"The value inside the method: {x}");
6363
}
6464
/* Output:
6565
The value before calling the method: 5

docs/csharp/language-reference/snippets/unsafe-code/Conversions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void Conversions()
2020
p++;
2121
}
2222
System.Console.WriteLine();
23-
System.Console.WriteLine("The value of the integer: {0}", number);
23+
System.Console.WriteLine($"The value of the integer: {number}");
2424

2525
/* Output:
2626
The 4 bytes of the integer: 00 04 00 00

docs/csharp/linq/get-started/snippets/WalkthroughWritingLinqQueries/Program.cs

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

44
// Create a data source by using a collection initializer.
@@ -237,7 +237,7 @@ from student in students
237237
select totalScore;
238238

239239
double averageScore = studentQuery.Average();
240-
Console.WriteLine("Class average score = {0}", averageScore);
240+
Console.WriteLine($"Class average score = {averageScore}");
241241

242242
// Output:
243243
// Class average score = 334.166666666667

0 commit comments

Comments
 (0)