Skip to content

Commit f7c7339

Browse files
authored
Convert to interpolated strings (standard, code-analysis, ml) (#45440)
1 parent 0eca2fb commit f7c7339

File tree

26 files changed

+89
-105
lines changed

26 files changed

+89
-105
lines changed

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1003.cs

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

33
namespace ca1003
44
{
@@ -35,7 +35,7 @@ public ClassThatHandlesEvent(ClassThatRaisesEvent eventRaiser)
3535

3636
private void HandleEvent(object sender, CustomEventArgs e)
3737
{
38-
Console.WriteLine("Event handled: {0}", e.info);
38+
Console.WriteLine($"Event handled: {e.info}");
3939
}
4040
}
4141

@@ -84,7 +84,7 @@ public ClassThatHandlesEvent(ClassThatRaisesEvent eventRaiser)
8484

8585
private void HandleEvent(object? sender, CustomEventArgs e)
8686
{
87-
Console.WriteLine("Event handled: {0}", e.info);
87+
Console.WriteLine($"Event handled: {e.info}");
8888
}
8989
}
9090

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1021.cs

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

33
namespace ca1021
44
{
@@ -142,8 +142,7 @@ static void UseTheComplicatedClass()
142142
// The call to the library.
143143
disposition[i] = BadRefAndOut.ReplyInformation(
144144
t, out reply[i], ref action[i]);
145-
Console.WriteLine("Reply: {0} Action: {1} return? {2} ",
146-
reply[i], action[i], disposition[i]);
145+
Console.WriteLine($"Reply: {reply[i]} Action: {action[i]} return? {disposition[i]} ");
147146
i++;
148147
}
149148
}

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1031.cs

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

44
namespace ca1031
@@ -18,7 +18,7 @@ public GenericExceptionsCaught(string inFile, string outFile)
1818
}
1919
catch (SystemException)
2020
{
21-
Console.WriteLine("Unable to open {0}.", inFile);
21+
Console.WriteLine($"Unable to open {inFile}.");
2222
}
2323

2424
try
@@ -27,7 +27,7 @@ public GenericExceptionsCaught(string inFile, string outFile)
2727
}
2828
catch
2929
{
30-
Console.WriteLine("Unable to open {0}.", outFile);
30+
Console.WriteLine($"Unable to open {outFile}.");
3131
}
3232
}
3333
}
@@ -47,7 +47,7 @@ public GenericExceptionsCaughtFixed(string inFile, string outFile)
4747
// Fix the first violation by catching a specific exception.
4848
catch (FileNotFoundException)
4949
{
50-
Console.WriteLine("Unable to open {0}.", inFile);
50+
Console.WriteLine($"Unable to open {inFile}.");
5151
};
5252

5353
// For functionally equivalent code, also catch
@@ -62,7 +62,7 @@ public GenericExceptionsCaughtFixed(string inFile, string outFile)
6262
// exception at the end of the catch block.
6363
catch
6464
{
65-
Console.WriteLine("Unable to open {0}.", outFile);
65+
Console.WriteLine($"Unable to open {outFile}.");
6666
throw;
6767
}
6868
}

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1036.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
using System.Globalization;
33

44
//<snippet1>
@@ -128,7 +128,7 @@ public static void Main1036(params string[] args)
128128
else
129129
answer = "equal to";
130130

131-
Console.WriteLine("{0} is {1} {2}", r1.Rating, answer, r2.Rating);
131+
Console.WriteLine($"{r1.Rating} is {answer} {r2.Rating}");
132132
}
133133
}
134134
//</snippet2>

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs

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

33
namespace ca1045
44
{
@@ -144,8 +144,7 @@ static void UseTheComplicatedClass()
144144
// The call to the library.
145145
disposition[i] = BadRefAndOut.ReplyInformation(
146146
t, out reply[i], ref action[i]);
147-
Console.WriteLine("Reply: {0} Action: {1} return? {2} ",
148-
reply[i], action[i], disposition[i]);
147+
Console.WriteLine($"Reply: {reply[i]} Action: {action[i]} return? {disposition[i]} ");
149148
i++;
150149
}
151150
}

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1046.cs

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

33
namespace ca1046
44
{
@@ -14,7 +14,7 @@ public MyReferenceType(int a, int b)
1414

1515
public override string ToString()
1616
{
17-
return String.Format("({0},{1})", a, b);
17+
return String.Format($"({a},{b})");
1818
}
1919
}
2020
//</snippet1>
@@ -28,10 +28,10 @@ public static void Main1046()
2828
MyReferenceType b = new MyReferenceType(2, 2);
2929
MyReferenceType c = a;
3030

31-
Console.WriteLine("a = new {0} and b = new {1} are equal? {2}", a, b, a.Equals(b) ? "Yes" : "No");
32-
Console.WriteLine("c and a are equal? {0}", c.Equals(a) ? "Yes" : "No");
33-
Console.WriteLine("b and a are == ? {0}", b == a ? "Yes" : "No");
34-
Console.WriteLine("c and a are == ? {0}", c == a ? "Yes" : "No");
31+
Console.WriteLine($"a = new {a} and b = new {b} are equal? {(a.Equals(b) ? "Yes" : "No")}");
32+
Console.WriteLine($"c and a are equal? {(c.Equals(a) ? "Yes" : "No")}");
33+
Console.WriteLine($"b and a are == ? {(b == a ? "Yes" : "No")}");
34+
Console.WriteLine($"c and a are == ? {(c == a ? "Yes" : "No")}");
3535
}
3636
}
3737
//</snippet2>

docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2214.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 ca2214
44
{
@@ -29,7 +29,7 @@ public DerivedType()
2929
}
3030
public override void DoSomething()
3131
{
32-
Console.WriteLine("Derived DoSomething is called - initialized ? {0}", initialized);
32+
Console.WriteLine($"Derived DoSomething is called - initialized ? {initialized}");
3333
}
3434
}
3535

docs/machine-learning/tutorials/snippets/github-issue-classification/csharp/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <SnippetAddUsings>
1+
// <SnippetAddUsings>
22
using Microsoft.ML;
33
using GitHubIssueClassification;
44
// </SnippetAddUsings>
@@ -186,5 +186,5 @@ void SaveModelAsFile(MLContext mlContext,DataViewSchema trainingDataViewSchema,
186186
mlContext.Model.Save(model, trainingDataViewSchema, _modelPath);
187187
// </SnippetSaveModel>
188188

189-
Console.WriteLine("The model is saved to {0}", _modelPath);
189+
Console.WriteLine($"The model is saved to {_modelPath}");
190190
}

docs/machine-learning/tutorials/snippets/phone-calls-anomaly-detection/csharp/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <SnippetAddUsings>
1+
// <SnippetAddUsings>
22
using Microsoft.ML;
33
using Microsoft.ML.TimeSeries;
44
using PhoneCallsAnomalyDetection;
@@ -38,7 +38,7 @@ int DetectPeriod(MLContext mlContext, IDataView phoneCalls)
3838
// </SnippetDetectSeasonality>
3939

4040
// <SnippetDisplayPeriod>
41-
Console.WriteLine("Period of the series is: {0}.", period);
41+
Console.WriteLine($"Period of the series is: {period}.");
4242
// </SnippetDisplayPeriod>
4343

4444
return period;

docs/orleans/host/snippets/ExampleExternalProgram.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Hosting;
33

44
using Orleans.Configuration;
@@ -84,7 +84,7 @@ class GameObserver : IGameObserver
8484
{
8585
public void UpdateGameScore(string score)
8686
{
87-
Console.WriteLine("New game score: {0}", score);
87+
Console.WriteLine($"New game score: {score}");
8888
}
8989
}
9090
// </gameobserver>

0 commit comments

Comments
 (0)