Skip to content

Commit c1aa305

Browse files
authored
use interpolated strings (#45454)
1 parent 464d28a commit c1aa305

File tree

83 files changed

+311
-409
lines changed

Some content is hidden

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

83 files changed

+311
-409
lines changed

docs/fundamentals/runtime-libraries/snippets/System.Collections.Generic/ListT/Overview/csharp/program.cs

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

@@ -59,8 +59,9 @@ public static void Main()
5959

6060
// Check the list for part #1734. This calls the IEquatable.Equals method
6161
// of the Part class, which checks the PartId for equality.
62-
Console.WriteLine("\nContains(\"1734\"): {0}",
63-
parts.Contains(new Part { PartId = 1734, PartName = "" }));
62+
Console.WriteLine($"""
63+
Contains("1734"): {parts.Contains(new Part { PartId = 1734, PartName = "" })}
64+
""");
6465

6566
// Insert a new item at position 2.
6667
Console.WriteLine("\nInsert(2, \"1834\")");
@@ -72,7 +73,7 @@ public static void Main()
7273
Console.WriteLine(aPart);
7374
}
7475

75-
Console.WriteLine("\nParts[3]: {0}", parts[3]);
76+
Console.WriteLine($"\nParts[3]: {parts[3]}");
7677

7778
Console.WriteLine("\nRemove(\"1534\")");
7879

docs/fundamentals/runtime-libraries/snippets/System.Collections.Generic/ListT/Overview/csharp/source.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33

44
public class Example2
@@ -9,7 +9,7 @@ public static void Main()
99
//<snippet2>
1010
List<string> dinosaurs = new List<string>();
1111

12-
Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
12+
Console.WriteLine($"\nCapacity: {dinosaurs.Capacity}");
1313

1414
dinosaurs.Add("Tyrannosaurus");
1515
dinosaurs.Add("Amargasaurus");
@@ -23,11 +23,10 @@ public static void Main()
2323
Console.WriteLine(dinosaur);
2424
}
2525

26-
Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
27-
Console.WriteLine("Count: {0}", dinosaurs.Count);
26+
Console.WriteLine($"\nCapacity: {dinosaurs.Capacity}");
27+
Console.WriteLine($"Count: {dinosaurs.Count}");
2828

29-
Console.WriteLine("\nContains(\"Deinonychus\"): {0}",
30-
dinosaurs.Contains("Deinonychus"));
29+
Console.WriteLine($"""\nContains("Deinonychus"): {dinosaurs.Contains("Deinonychus")}""");
3130

3231
Console.WriteLine("\nInsert(2, \"Compsognathus\")");
3332
dinosaurs.Insert(2, "Compsognathus");
@@ -40,7 +39,7 @@ public static void Main()
4039

4140
//<snippet3>
4241
// Shows accessing the list using the Item property.
43-
Console.WriteLine("\ndinosaurs[3]: {0}", dinosaurs[3]);
42+
Console.WriteLine($"\ndinosaurs[3]: {dinosaurs[3]}");
4443
//</snippet3>
4544

4645
Console.WriteLine("\nRemove(\"Compsognathus\")");
@@ -54,13 +53,13 @@ public static void Main()
5453

5554
dinosaurs.TrimExcess();
5655
Console.WriteLine("\nTrimExcess()");
57-
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
58-
Console.WriteLine("Count: {0}", dinosaurs.Count);
56+
Console.WriteLine($"Capacity: {dinosaurs.Capacity}");
57+
Console.WriteLine($"Count: {dinosaurs.Count}");
5958

6059
dinosaurs.Clear();
6160
Console.WriteLine("\nClear()");
62-
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity);
63-
Console.WriteLine("Count: {0}", dinosaurs.Count);
61+
Console.WriteLine($"Capacity: {dinosaurs.Capacity}");
62+
Console.WriteLine($"Count: {dinosaurs.Count}");
6463

6564
/* This code example produces the following output:
6665

docs/fundamentals/runtime-libraries/snippets/System.Diagnostics/PerformanceCounter/NextValue/csharp/elapsedtime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Notice that the sample is conditionally compiled for Everett vs.
1+
// Notice that the sample is conditionally compiled for Everett vs.
22
// Whidbey builds. Whidbey introduced new APIs that are not available
33
// in Everett. Snippet IDs do not overlap between Whidbey and Everett;
44
// Snippet #1 is Everett, Snippet #2 and #3 are Whidbey.
@@ -169,7 +169,7 @@ public static void CollectSamples()
169169
}
170170
else
171171
{
172-
Console.WriteLine("Category exists - {0}", categoryName);
172+
Console.WriteLine($"Category exists - {categoryName}");
173173
}
174174

175175
//<Snippet3>

docs/fundamentals/runtime-libraries/snippets/System.Dynamic/ExpandoObject/Overview/csharp/program.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
@@ -89,11 +89,10 @@ static void Main(string[] args)
8989
}
9090
private static void WritePerson(dynamic person)
9191
{
92-
Console.WriteLine("{0} is {1} years old.",
93-
person.Name, person.Age);
92+
Console.WriteLine($"{person.Name} is {person.Age} years old.");
9493
// The following statement causes an exception
9594
// if you pass the employee object.
96-
// Console.WriteLine("Manages {0} people", person.TeamSize);
95+
// Console.WriteLine($"Manages {person.TeamSize} people");
9796
}
9897
}
9998
// This code example produces the following output:
@@ -120,7 +119,7 @@ static void Test()
120119
private static void HandlePropertyChanges(
121120
object sender, PropertyChangedEventArgs e)
122121
{
123-
Console.WriteLine("{0} has changed.", e.PropertyName);
122+
Console.WriteLine($"{e.PropertyName} has changed.");
124123
}
125124
}
126125
//</Snippet7>

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentCulture/csharp/Async1.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet14>
1+
// <Snippet14>
22
using System;
33
using System.Collections.Generic;
44
using System.Globalization;
@@ -11,22 +11,16 @@ public class Example14
1111
public static async Task Main()
1212
{
1313
var tasks = new List<Task>();
14-
Console.WriteLine("The current culture is {0}",
15-
Thread.CurrentThread.CurrentCulture.Name);
14+
Console.WriteLine($"The current culture is {Thread.CurrentThread.CurrentCulture.Name}");
1615
Thread.CurrentThread.CurrentCulture = new CultureInfo("pt-BR");
1716
// Change the current culture to Portuguese (Brazil).
18-
Console.WriteLine("Current culture changed to {0}",
19-
Thread.CurrentThread.CurrentCulture.Name);
20-
Console.WriteLine("Application thread is thread {0}",
21-
Thread.CurrentThread.ManagedThreadId);
17+
Console.WriteLine($"Current culture changed to {Thread.CurrentThread.CurrentCulture.Name}");
18+
Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}");
2219
// Launch six tasks and display their current culture.
2320
for (int ctr = 0; ctr <= 5; ctr++)
2421
tasks.Add(Task.Run(() =>
2522
{
26-
Console.WriteLine("Culture of task {0} on thread {1} is {2}",
27-
Task.CurrentId,
28-
Thread.CurrentThread.ManagedThreadId,
29-
Thread.CurrentThread.CurrentCulture.Name);
23+
Console.WriteLine($"Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentCulture.Name}");
3024
}));
3125

3226
await Task.WhenAll(tasks.ToArray());

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentCulture/csharp/Get1.cs

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

@@ -7,8 +7,7 @@ public class Example5
77
public static void Main()
88
{
99
CultureInfo culture = CultureInfo.CurrentCulture;
10-
Console.WriteLine("The current culture is {0} [{1}]",
11-
culture.NativeName, culture.Name);
10+
Console.WriteLine($"The current culture is {culture.NativeName} [{culture.Name}]");
1211
}
1312
}
1413
// The example displays output like the following:

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentCulture/csharp/changeculture11.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet11>
1+
// <Snippet11>
22
using System;
33
using System.Globalization;
44
using System.Threading;
@@ -7,10 +7,7 @@ public class Info11 : MarshalByRefObject
77
{
88
public void ShowCurrentCulture()
99
{
10-
Console.WriteLine("Culture of {0} in application domain {1}: {2}",
11-
Thread.CurrentThread.Name,
12-
AppDomain.CurrentDomain.FriendlyName,
13-
CultureInfo.CurrentCulture.Name);
10+
Console.WriteLine($"Culture of {Thread.CurrentThread.Name} in application domain {AppDomain.CurrentDomain.FriendlyName}: {CultureInfo.CurrentCulture.Name}");
1411
}
1512
}
1613

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentCulture/csharp/specific12.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet12>
1+
// <Snippet12>
22
using System;
33
using System.Globalization;
44
using System.Threading;
@@ -9,14 +9,12 @@ public static void Main()
99
{
1010
double value = 1634.92;
1111
CultureInfo.CurrentCulture = new CultureInfo("fr-CA");
12-
Console.WriteLine("Current Culture: {0}",
13-
CultureInfo.CurrentCulture.Name);
14-
Console.WriteLine("{0:C2}\n", value);
12+
Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}");
13+
Console.WriteLine($"{value:C2}\n");
1514

1615
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr");
17-
Console.WriteLine("Current Culture: {0}",
18-
CultureInfo.CurrentCulture.Name);
19-
Console.WriteLine("{0:C2}", value);
16+
Console.WriteLine($"Current Culture: {CultureInfo.CurrentCulture.Name}");
17+
Console.WriteLine($"{value:C2}");
2018
}
2119
}
2220
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentUICulture/csharp/Async1.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet14>
1+
// <Snippet14>
22
using System;
33
using System.Collections.Generic;
44
using System.Globalization;
@@ -11,22 +11,16 @@ public class Example
1111
public static async Task Main()
1212
{
1313
var tasks = new List<Task>();
14-
Console.WriteLine("The current UI culture is {0}",
15-
Thread.CurrentThread.CurrentUICulture.Name);
14+
Console.WriteLine($"The current UI culture is {Thread.CurrentThread.CurrentUICulture.Name}");
1615
Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR");
1716
// Change the current UI culture to Portuguese (Brazil).
18-
Console.WriteLine("Current UI culture changed to {0}",
19-
Thread.CurrentThread.CurrentUICulture.Name);
20-
Console.WriteLine("Application thread is thread {0}",
21-
Thread.CurrentThread.ManagedThreadId);
17+
Console.WriteLine($"Current UI culture changed to {Thread.CurrentThread.CurrentUICulture.Name}");
18+
Console.WriteLine($"Application thread is thread {Thread.CurrentThread.ManagedThreadId}");
2219
// Launch six tasks and display their current culture.
2320
for (int ctr = 0; ctr <= 5; ctr++)
2421
tasks.Add(Task.Run(() =>
2522
{
26-
Console.WriteLine("UI Culture of task {0} on thread {1} is {2}",
27-
Task.CurrentId,
28-
Thread.CurrentThread.ManagedThreadId,
29-
Thread.CurrentThread.CurrentUICulture.Name);
23+
Console.WriteLine($"UI Culture of task {Task.CurrentId} on thread {Thread.CurrentThread.ManagedThreadId} is {Thread.CurrentThread.CurrentUICulture.Name}");
3024
}));
3125

3226
await Task.WhenAll(tasks.ToArray());

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentUICulture/csharp/Get1.cs

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

@@ -7,8 +7,7 @@ public class Example2
77
public static void Main()
88
{
99
CultureInfo culture = CultureInfo.CurrentUICulture;
10-
Console.WriteLine("The current UI culture is {0} [{1}]",
11-
culture.NativeName, culture.Name);
10+
Console.WriteLine($"The current UI culture is {culture.NativeName} [{culture.Name}]");
1211
}
1312
}
1413
// The example displays output like the following:

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/CurrentUICulture/csharp/currentuiculture1.cs

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

55
public class Example1
66
{
77
public static void Main()
88
{
9-
Console.WriteLine("The current UI culture: {0}",
10-
CultureInfo.CurrentUICulture.Name);
9+
Console.WriteLine($"The current UI culture: {CultureInfo.CurrentUICulture.Name}");
1110

1211
CultureInfo.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
13-
Console.WriteLine("The current UI culture: {0}",
14-
CultureInfo.CurrentUICulture.Name);
12+
Console.WriteLine($"The current UI culture: {CultureInfo.CurrentUICulture.Name}");
1513
}
1614
}
1715
// The example displays output like the following:

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/InvariantCulture/csharp/persist1.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet1>
1+
// <Snippet1>
22
using System;
33
using System.IO;
44
using System.Globalization;
@@ -24,22 +24,20 @@ public static void Main()
2424
String input;
2525
while ((input = sr.ReadLine()) != null)
2626
{
27-
Console.WriteLine("Stored data: {0}\n" , input);
27+
Console.WriteLine($"Stored data: {input}\n");
2828

2929
// Parse the stored string.
3030
DateTime dtOut = DateTime.Parse(input, invC, DateTimeStyles.RoundtripKind);
3131

3232
// Create a French (France) CultureInfo object.
3333
CultureInfo frFr = new CultureInfo("fr-FR");
3434
// Displays the date formatted for the "fr-FR" culture.
35-
Console.WriteLine("Date formatted for the {0} culture: {1}" ,
36-
frFr.Name, dtOut.ToString("f", frFr));
35+
Console.WriteLine($"Date formatted for the {frFr.Name} culture: {dtOut.ToString("f", frFr)}");
3736

3837
// Creates a German (Germany) CultureInfo object.
3938
CultureInfo deDe= new CultureInfo("de-De");
4039
// Displays the date formatted for the "de-DE" culture.
41-
Console.WriteLine("Date formatted for {0} culture: {1}" ,
42-
deDe.Name, dtOut.ToString("f", deDe));
40+
Console.WriteLine($"Date formatted for {deDe.Name} culture: {dtOut.ToString("f", deDe)}");
4341
}
4442
sr.Close();
4543
}

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/csharp/appdomainex1.cs

Lines changed: 5 additions & 5 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

@@ -55,14 +55,14 @@ public class Info : MarshalByRefObject
5555
{
5656
public void DisplayDate()
5757
{
58-
Console.WriteLine("Today is {0:D}", DateTime.Now);
58+
Console.WriteLine($"Today is {DateTime.Now:D}");
5959
}
6060

6161
public void DisplayCultures()
6262
{
63-
Console.WriteLine("Application domain is {0}", AppDomain.CurrentDomain.Id);
64-
Console.WriteLine("Default Culture: {0}", CultureInfo.DefaultThreadCurrentCulture);
65-
Console.WriteLine("Default UI Culture: {0}", CultureInfo.DefaultThreadCurrentUICulture);
63+
Console.WriteLine($"Application domain is {AppDomain.CurrentDomain.Id}");
64+
Console.WriteLine($"Default Culture: {CultureInfo.DefaultThreadCurrentCulture}");
65+
Console.WriteLine($"Default UI Culture: {CultureInfo.DefaultThreadCurrentUICulture}");
6666
}
6767
}
6868
// The example displays the following output:

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/csharp/asyncculture3.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <Snippet3>
1+
// <Snippet3>
22
using System;
33
using System.Globalization;
44
using System.Threading;
@@ -22,18 +22,15 @@ public static void Main()
2222
return output;
2323
};
2424

25-
Console.WriteLine("The example is running on thread {0}",
26-
Thread.CurrentThread.ManagedThreadId);
25+
Console.WriteLine($"The example is running on thread {Thread.CurrentThread.ManagedThreadId}");
2726
// Make the current culture different from the system culture.
28-
Console.WriteLine("The current culture is {0}",
29-
CultureInfo.CurrentCulture.Name);
27+
Console.WriteLine($"The current culture is {CultureInfo.CurrentCulture.Name}");
3028
if (CultureInfo.CurrentCulture.Name == "fr-FR")
3129
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
3230
else
3331
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
3432

35-
Console.WriteLine("Changed the current culture to {0}.\n",
36-
CultureInfo.CurrentCulture.Name);
33+
Console.WriteLine($"Changed the current culture to {CultureInfo.CurrentCulture.Name}.\n");
3734
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
3835

3936
// Execute the delegate synchronously.

docs/fundamentals/runtime-libraries/snippets/System.Globalization/CultureInfo/csharp/change1.cs

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

@@ -7,16 +7,15 @@ public class ChangeEx1
77
public static void Main()
88
{
99
CultureInfo current = CultureInfo.CurrentCulture;
10-
Console.WriteLine("The current culture is {0}", current.Name);
10+
Console.WriteLine($"The current culture is {current.Name}");
1111
CultureInfo newCulture;
1212
if (current.Name.Equals("fr-FR"))
1313
newCulture = new CultureInfo("fr-LU");
1414
else
1515
newCulture = new CultureInfo("fr-FR");
1616

1717
CultureInfo.CurrentCulture = newCulture;
18-
Console.WriteLine("The current culture is now {0}",
19-
CultureInfo.CurrentCulture.Name);
18+
Console.WriteLine($"The current culture is now {CultureInfo.CurrentCulture.Name}");
2019
}
2120
}
2221
// The example displays output like the following:

0 commit comments

Comments
 (0)