diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1003.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1003.cs
index 79e62603330c0..b57fc4804946e 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1003.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1003.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace ca1003
{
@@ -35,7 +35,7 @@ public ClassThatHandlesEvent(ClassThatRaisesEvent eventRaiser)
private void HandleEvent(object sender, CustomEventArgs e)
{
- Console.WriteLine("Event handled: {0}", e.info);
+ Console.WriteLine($"Event handled: {e.info}");
}
}
@@ -84,7 +84,7 @@ public ClassThatHandlesEvent(ClassThatRaisesEvent eventRaiser)
private void HandleEvent(object? sender, CustomEventArgs e)
{
- Console.WriteLine("Event handled: {0}", e.info);
+ Console.WriteLine($"Event handled: {e.info}");
}
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1021.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1021.cs
index 3e79a197f9aad..7de7fe95d472f 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1021.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1021.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace ca1021
{
@@ -142,8 +142,7 @@ static void UseTheComplicatedClass()
// The call to the library.
disposition[i] = BadRefAndOut.ReplyInformation(
t, out reply[i], ref action[i]);
- Console.WriteLine("Reply: {0} Action: {1} return? {2} ",
- reply[i], action[i], disposition[i]);
+ Console.WriteLine($"Reply: {reply[i]} Action: {action[i]} return? {disposition[i]} ");
i++;
}
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1031.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1031.cs
index b530fe51f11d1..c2de821540bda 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1031.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1031.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
namespace ca1031
@@ -18,7 +18,7 @@ public GenericExceptionsCaught(string inFile, string outFile)
}
catch (SystemException)
{
- Console.WriteLine("Unable to open {0}.", inFile);
+ Console.WriteLine($"Unable to open {inFile}.");
}
try
@@ -27,7 +27,7 @@ public GenericExceptionsCaught(string inFile, string outFile)
}
catch
{
- Console.WriteLine("Unable to open {0}.", outFile);
+ Console.WriteLine($"Unable to open {outFile}.");
}
}
}
@@ -47,7 +47,7 @@ public GenericExceptionsCaughtFixed(string inFile, string outFile)
// Fix the first violation by catching a specific exception.
catch (FileNotFoundException)
{
- Console.WriteLine("Unable to open {0}.", inFile);
+ Console.WriteLine($"Unable to open {inFile}.");
};
// For functionally equivalent code, also catch
@@ -62,7 +62,7 @@ public GenericExceptionsCaughtFixed(string inFile, string outFile)
// exception at the end of the catch block.
catch
{
- Console.WriteLine("Unable to open {0}.", outFile);
+ Console.WriteLine($"Unable to open {outFile}.");
throw;
}
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1036.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1036.cs
index a7443668d5edc..939daf9bf15ff 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1036.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1036.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Globalization;
//
@@ -128,7 +128,7 @@ public static void Main1036(params string[] args)
else
answer = "equal to";
- Console.WriteLine("{0} is {1} {2}", r1.Rating, answer, r2.Rating);
+ Console.WriteLine($"{r1.Rating} is {answer} {r2.Rating}");
}
}
//
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs
index 52adfffc938bb..cab84b003229e 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1045.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace ca1045
{
@@ -144,8 +144,7 @@ static void UseTheComplicatedClass()
// The call to the library.
disposition[i] = BadRefAndOut.ReplyInformation(
t, out reply[i], ref action[i]);
- Console.WriteLine("Reply: {0} Action: {1} return? {2} ",
- reply[i], action[i], disposition[i]);
+ Console.WriteLine($"Reply: {reply[i]} Action: {action[i]} return? {disposition[i]} ");
i++;
}
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1046.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1046.cs
index 0bfb03d5fcde0..3848b3cfafab2 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1046.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1046.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace ca1046
{
@@ -14,7 +14,7 @@ public MyReferenceType(int a, int b)
public override string ToString()
{
- return String.Format("({0},{1})", a, b);
+ return String.Format($"({a},{b})");
}
}
//
@@ -28,10 +28,10 @@ public static void Main1046()
MyReferenceType b = new MyReferenceType(2, 2);
MyReferenceType c = a;
- Console.WriteLine("a = new {0} and b = new {1} are equal? {2}", a, b, a.Equals(b) ? "Yes" : "No");
- Console.WriteLine("c and a are equal? {0}", c.Equals(a) ? "Yes" : "No");
- Console.WriteLine("b and a are == ? {0}", b == a ? "Yes" : "No");
- Console.WriteLine("c and a are == ? {0}", c == a ? "Yes" : "No");
+ Console.WriteLine($"a = new {a} and b = new {b} are equal? {(a.Equals(b) ? "Yes" : "No")}");
+ Console.WriteLine($"c and a are equal? {(c.Equals(a) ? "Yes" : "No")}");
+ Console.WriteLine($"b and a are == ? {(b == a ? "Yes" : "No")}");
+ Console.WriteLine($"c and a are == ? {(c == a ? "Yes" : "No")}");
}
}
//
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2214.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2214.cs
index 48f586b2e3aff..0683515678163 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2214.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2214.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
namespace ca2214
{
@@ -29,7 +29,7 @@ public DerivedType()
}
public override void DoSomething()
{
- Console.WriteLine("Derived DoSomething is called - initialized ? {0}", initialized);
+ Console.WriteLine($"Derived DoSomething is called - initialized ? {initialized}");
}
}
diff --git a/docs/machine-learning/tutorials/snippets/github-issue-classification/csharp/Program.cs b/docs/machine-learning/tutorials/snippets/github-issue-classification/csharp/Program.cs
index bb7aa435119f2..e227d480221db 100644
--- a/docs/machine-learning/tutorials/snippets/github-issue-classification/csharp/Program.cs
+++ b/docs/machine-learning/tutorials/snippets/github-issue-classification/csharp/Program.cs
@@ -1,4 +1,4 @@
-//
+//
using Microsoft.ML;
using GitHubIssueClassification;
//
@@ -186,5 +186,5 @@ void SaveModelAsFile(MLContext mlContext,DataViewSchema trainingDataViewSchema,
mlContext.Model.Save(model, trainingDataViewSchema, _modelPath);
//
- Console.WriteLine("The model is saved to {0}", _modelPath);
+ Console.WriteLine($"The model is saved to {_modelPath}");
}
diff --git a/docs/machine-learning/tutorials/snippets/phone-calls-anomaly-detection/csharp/Program.cs b/docs/machine-learning/tutorials/snippets/phone-calls-anomaly-detection/csharp/Program.cs
index 83427858ca13e..65eb1e4325ccd 100644
--- a/docs/machine-learning/tutorials/snippets/phone-calls-anomaly-detection/csharp/Program.cs
+++ b/docs/machine-learning/tutorials/snippets/phone-calls-anomaly-detection/csharp/Program.cs
@@ -1,4 +1,4 @@
-//
+//
using Microsoft.ML;
using Microsoft.ML.TimeSeries;
using PhoneCallsAnomalyDetection;
@@ -38,7 +38,7 @@ int DetectPeriod(MLContext mlContext, IDataView phoneCalls)
//
//
- Console.WriteLine("Period of the series is: {0}.", period);
+ Console.WriteLine($"Period of the series is: {period}.");
//
return period;
diff --git a/docs/orleans/host/snippets/ExampleExternalProgram.cs b/docs/orleans/host/snippets/ExampleExternalProgram.cs
index 0eda9288ad67f..c8a9b5f83e63d 100644
--- a/docs/orleans/host/snippets/ExampleExternalProgram.cs
+++ b/docs/orleans/host/snippets/ExampleExternalProgram.cs
@@ -1,4 +1,4 @@
-using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans.Configuration;
@@ -84,7 +84,7 @@ class GameObserver : IGameObserver
{
public void UpdateGameScore(string score)
{
- Console.WriteLine("New game score: {0}", score);
+ Console.WriteLine($"New game score: {score}");
}
}
//
diff --git a/docs/standard/base-types/snippets/composite-formatting/net/csharp/Program.cs b/docs/standard/base-types/snippets/composite-formatting/net/csharp/Program.cs
index badcf2e1b4767..fa8705dc13c29 100644
--- a/docs/standard/base-types/snippets/composite-formatting/net/csharp/Program.cs
+++ b/docs/standard/base-types/snippets/composite-formatting/net/csharp/Program.cs
@@ -1,4 +1,4 @@
-
+
void Index()
{
//
@@ -73,7 +73,7 @@ void Examples_Currency()
{
//
int myNumber = 100;
- Console.WriteLine("{0:C}", myNumber);
+ Console.WriteLine($"{myNumber:C}");
// The example displays the following output
// if en-US is the current culture:
diff --git a/docs/standard/base-types/snippets/how-to-display-milliseconds-in-date-and-time-values/csharp/Program.cs b/docs/standard/base-types/snippets/how-to-display-milliseconds-in-date-and-time-values/csharp/Program.cs
index 41c30b61274da..239d8233caba5 100644
--- a/docs/standard/base-types/snippets/how-to-display-milliseconds-in-date-and-time-values/csharp/Program.cs
+++ b/docs/standard/base-types/snippets/how-to-display-milliseconds-in-date-and-time-values/csharp/Program.cs
@@ -1,4 +1,4 @@
-//
+//
using System.Globalization;
using System.Text.RegularExpressions;
@@ -37,7 +37,7 @@
}
catch (FormatException)
{
- Console.WriteLine("Unable to convert {0} to a date.", dateString);
+ Console.WriteLine($"Unable to convert {dateString} to a date.");
}
// The example displays the following output if the current culture is en-US:
// Millisecond component only: 126
diff --git a/docs/standard/base-types/snippets/parse-strings/csharp/regex.cs b/docs/standard/base-types/snippets/parse-strings/csharp/regex.cs
index 5e40ed21dda54..5f0c8adae39bc 100644
--- a/docs/standard/base-types/snippets/parse-strings/csharp/regex.cs
+++ b/docs/standard/base-types/snippets/parse-strings/csharp/regex.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
public class RegExExamples
{
@@ -20,16 +20,16 @@ public static void Example1()
switch (m.Groups[2].Value)
{
case "+":
- Console.WriteLine("{0} = {1}", m.Value, value1 + value2);
+ Console.WriteLine($"{m.Value} = {value1 + value2}");
break;
case "-":
- Console.WriteLine("{0} = {1}", m.Value, value1 - value2);
+ Console.WriteLine($"{m.Value} = {value1 - value2}");
break;
case "*":
- Console.WriteLine("{0} = {1}", m.Value, value1 * value2);
+ Console.WriteLine($"{m.Value} = {value1 * value2}");
break;
case "/":
- Console.WriteLine("{0} = {1:N2}", m.Value, value1 / value2);
+ Console.WriteLine($"{m.Value} = {value1 / value2:N2}");
break;
}
}
@@ -57,7 +57,7 @@ public static void Example2()
foreach (System.Text.RegularExpressions.Match m in
System.Text.RegularExpressions.Regex.Matches(input, pattern))
{
- Console.WriteLine("{0}: {1}", ++ctr, m.Groups[1].Value);
+ Console.WriteLine($"{++ctr}: {m.Groups[1].Value}");
}
// The example displays the following output:
diff --git a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking1.cs b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking1.cs
index b1894b7627723..37821371e3804 100644
--- a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking1.cs
+++ b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking1.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Text.RegularExpressions;
@@ -9,8 +9,7 @@ public static void Run()
string input = "needing a reed";
string pattern = @"e{2}\w\b";
foreach (Match match in Regex.Matches(input, pattern))
- Console.WriteLine("{0} found at position {1}",
- match.Value, match.Index);
+ Console.WriteLine($"{match.Value} found at position {match.Index}");
}
}
// The example displays the following output:
diff --git a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking5.cs b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking5.cs
index 8ea6b366c6f10..dda3657536bd8 100644
--- a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking5.cs
+++ b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking5.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
@@ -15,13 +15,13 @@ public static void Run()
sw = Stopwatch.StartNew();
result = Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase);
sw.Stop();
- Console.WriteLine("Match: {0} in {1}", result, sw.Elapsed);
+ Console.WriteLine($"Match: {result} in {sw.Elapsed}");
string behindPattern = @"^[0-9A-Z][-.\w]*(?<=[0-9A-Z])@";
sw = Stopwatch.StartNew();
result = Regex.IsMatch(input, behindPattern, RegexOptions.IgnoreCase);
sw.Stop();
- Console.WriteLine("Match with Lookbehind: {0} in {1}", result, sw.Elapsed);
+ Console.WriteLine($"Match with Lookbehind: {result} in {sw.Elapsed}");
}
}
// The example displays output similar to the following:
diff --git a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking6.cs b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking6.cs
index 81ca8ce404225..09d92fc74a653 100644
--- a/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking6.cs
+++ b/docs/standard/base-types/snippets/regex-backtracking/csharp/backtracking6.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
@@ -15,13 +15,13 @@ public static void Run()
sw = Stopwatch.StartNew();
result = Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase);
sw.Stop();
- Console.WriteLine("{0} in {1}", result, sw.Elapsed);
+ Console.WriteLine($"{result} in {sw.Elapsed}");
string aheadPattern = @"^((?=[A-Z])\w+\.)*[A-Z]\w*$";
sw = Stopwatch.StartNew();
result = Regex.IsMatch(input, aheadPattern, RegexOptions.IgnoreCase);
sw.Stop();
- Console.WriteLine("{0} in {1}", result, sw.Elapsed);
+ Console.WriteLine($"{result} in {sw.Elapsed}");
}
}
// The example displays the following output:
diff --git a/docs/standard/base-types/snippets/regex/csharp/compare1.cs b/docs/standard/base-types/snippets/regex/csharp/compare1.cs
index 637eb9dc4a1f0..5c89c47f0ea60 100644
--- a/docs/standard/base-types/snippets/regex/csharp/compare1.cs
+++ b/docs/standard/base-types/snippets/regex/csharp/compare1.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Diagnostics;
using System.Net.Http;
using System.Text.RegularExpressions;
@@ -37,7 +37,7 @@ public async static Task RunIt()
break;
}
sw.Stop();
- Console.WriteLine(" {0} matches in {1}", ctr, sw.Elapsed);
+ Console.WriteLine($" {ctr} matches in {sw.Elapsed}");
// Read first ten sentences with compiled regex.
Console.WriteLine("10 Sentences with Compiled Regex:");
@@ -54,7 +54,7 @@ public async static Task RunIt()
break;
}
sw.Stop();
- Console.WriteLine(" {0} matches in {1}", ctr, sw.Elapsed);
+ Console.WriteLine($" {ctr} matches in {sw.Elapsed}");
// Read first ten sentences with source-generated regex.
Console.WriteLine("10 Sentences with Source-generated Regex:");
@@ -70,7 +70,7 @@ public async static Task RunIt()
break;
}
sw.Stop();
- Console.WriteLine(" {0} matches in {1}", ctr, sw.Elapsed);
+ Console.WriteLine($" {ctr} matches in {sw.Elapsed}");
// Read all sentences with interpreted regex.
Console.WriteLine("All Sentences with Interpreted Regex:");
@@ -85,7 +85,7 @@ public async static Task RunIt()
match = match.NextMatch();
}
sw.Stop();
- Console.WriteLine(" {0:N0} matches in {1}", matches, sw.Elapsed);
+ Console.WriteLine($" {matches:N0} matches in {sw.Elapsed}");
// Read all sentences with compiled regex.
Console.WriteLine("All Sentences with Compiled Regex:");
@@ -101,7 +101,7 @@ public async static Task RunIt()
match = match.NextMatch();
}
sw.Stop();
- Console.WriteLine(" {0:N0} matches in {1}", matches, sw.Elapsed);
+ Console.WriteLine($" {matches:N0} matches in {sw.Elapsed}");
// Read all sentences with source-generated regex.
Console.WriteLine("All Sentences with Source-generated Regex:");
@@ -115,7 +115,7 @@ public async static Task RunIt()
match = match.NextMatch();
}
sw.Stop();
- Console.WriteLine(" {0:N0} matches in {1}", matches, sw.Elapsed);
+ Console.WriteLine($" {matches:N0} matches in {sw.Elapsed}");
return;
}
diff --git a/docs/standard/base-types/snippets/regex/csharp/compile2.cs b/docs/standard/base-types/snippets/regex/csharp/compile2.cs
index 54f9dcbb0eebe..408d6c849a126 100644
--- a/docs/standard/base-types/snippets/regex/csharp/compile2.cs
+++ b/docs/standard/base-types/snippets/regex/csharp/compile2.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.IO;
using System.Text.RegularExpressions;
@@ -14,7 +14,7 @@ public static void Main()
inFile.Close();
MatchCollection matches = pattern.Matches(input);
- Console.WriteLine("Found {0:N0} sentences.", matches.Count);
+ Console.WriteLine($"Found {matches.Count:N0} sentences.");
}
}
// The example displays the following output:
diff --git a/docs/standard/base-types/snippets/regex/csharp/group1.cs b/docs/standard/base-types/snippets/regex/csharp/group1.cs
index 79b0274b2acbe..6289d61f1023b 100644
--- a/docs/standard/base-types/snippets/regex/csharp/group1.cs
+++ b/docs/standard/base-types/snippets/regex/csharp/group1.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Text.RegularExpressions;
@@ -11,18 +11,15 @@ public static void Main()
foreach (Match match in Regex.Matches(input, pattern))
{
- Console.WriteLine("Match: '{0}' at index {1}.",
- match.Value, match.Index);
+ Console.WriteLine($"Match: '{match.Value}' at index {match.Index}.");
int grpCtr = 0;
foreach (Group grp in match.Groups)
{
- Console.WriteLine(" Group {0}: '{1}' at index {2}.",
- grpCtr, grp.Value, grp.Index);
+ Console.WriteLine($" Group {grpCtr}: '{grp.Value}' at index {grp.Index}.");
int capCtr = 0;
foreach (Capture cap in grp.Captures)
{
- Console.WriteLine(" Capture {0}: '{1}' at {2}.",
- capCtr, cap.Value, cap.Index);
+ Console.WriteLine($" Capture {capCtr}: '{cap.Value}' at {cap.Index}.");
capCtr++;
}
grpCtr++;
diff --git a/docs/standard/base-types/snippets/regex/csharp/group2.cs b/docs/standard/base-types/snippets/regex/csharp/group2.cs
index 1df6a6d296aee..d22a44adf8c77 100644
--- a/docs/standard/base-types/snippets/regex/csharp/group2.cs
+++ b/docs/standard/base-types/snippets/regex/csharp/group2.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Text.RegularExpressions;
@@ -11,18 +11,15 @@ public static void Main()
foreach (Match match in Regex.Matches(input, pattern))
{
- Console.WriteLine("Match: '{0}' at index {1}.",
- match.Value, match.Index);
+ Console.WriteLine($"Match: '{match.Value}' at index {match.Index}.");
int grpCtr = 0;
foreach (Group grp in match.Groups)
{
- Console.WriteLine(" Group {0}: '{1}' at index {2}.",
- grpCtr, grp.Value, grp.Index);
+ Console.WriteLine($" Group {grpCtr}: '{grp.Value}' at index {grp.Index}.");
int capCtr = 0;
foreach (Capture cap in grp.Captures)
{
- Console.WriteLine(" Capture {0}: '{1}' at {2}.",
- capCtr, cap.Value, cap.Index);
+ Console.WriteLine($" Capture {capCtr}: '{cap.Value}' at {cap.Index}.");
capCtr++;
}
grpCtr++;
diff --git a/docs/standard/base-types/snippets/regex/csharp/timeout1.cs b/docs/standard/base-types/snippets/regex/csharp/timeout1.cs
index 9b70ac01d7ff6..ac42c688bc407 100644
--- a/docs/standard/base-types/snippets/regex/csharp/timeout1.cs
+++ b/docs/standard/base-types/snippets/regex/csharp/timeout1.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Collections.Generic;
using System.IO;
@@ -13,18 +13,17 @@ public static void Main()
try
{
var info = util.GetWordData(title);
- Console.WriteLine("Words: {0:N0}", info.Item1);
- Console.WriteLine("Average Word Length: {0:N2} characters", info.Item2);
+ Console.WriteLine($"Words: {info.Item1:N0}");
+ Console.WriteLine($"Average Word Length: {info.Item2:N2} characters");
}
catch (IOException e)
{
- Console.WriteLine("IOException reading file '{0}'", title);
+ Console.WriteLine($"IOException reading file '{title}'");
Console.WriteLine(e.Message);
}
catch (RegexMatchTimeoutException e)
{
- Console.WriteLine("The operation timed out after {0:N0} milliseconds",
- e.MatchTimeout.TotalMilliseconds);
+ Console.WriteLine($"The operation timed out after {e.MatchTimeout.TotalMilliseconds:N0} milliseconds");
}
}
}
diff --git a/docs/standard/datetime/snippets/instantiating-a-datetimeoffset-object/csharp/Instantiate.cs b/docs/standard/datetime/snippets/instantiating-a-datetimeoffset-object/csharp/Instantiate.cs
index d6c5b5da506ce..35d6b353b7711 100644
--- a/docs/standard/datetime/snippets/instantiating-a-datetimeoffset-object/csharp/Instantiate.cs
+++ b/docs/standard/datetime/snippets/instantiating-a-datetimeoffset-object/csharp/Instantiate.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Globalization;
public class Class1
@@ -86,8 +86,7 @@ private static void CallDateTimeConstructors()
}
catch (ArgumentException)
{
- Console.WriteLine("Attempt to create DateTimeOffset value from {0} failed.",
- targetTime);
+ Console.WriteLine($"Attempt to create DateTimeOffset value from {targetTime} failed.");
}
// Throws exception and displays the following to the console:
// Attempt to create DateTimeOffset value from 5/1/2008 8:30:00 AM +00:00 failed.
@@ -131,8 +130,7 @@ private static void CallDateTimeWithOffsetConstructors()
}
catch (ArgumentException)
{
- Console.WriteLine("Attempt to create DateTimeOffset value from {0} failed.",
- utcTime);
+ Console.WriteLine($"Attempt to create DateTimeOffset value from {utcTime} failed.");
}
// Throws exception and displays the following to the console:
// Attempt to create DateTimeOffset value from 5/1/2008 8:30:00 AM failed.
@@ -155,8 +153,7 @@ private static void CallDateTimeWithOffsetConstructors()
}
catch (ArgumentException)
{
- Console.WriteLine("Attempt to create DateTimeOffset value from {0} failed.",
- localTime);
+ Console.WriteLine($"Attempt to create DateTimeOffset value from {localTime} failed.");
}
// Throws exception and displays the following to the console:
// Attempt to create DateTimeOffset value from 5/1/2008 8:30:00 AM failed.
@@ -210,14 +207,14 @@ private static void ParseTimeString()
}
catch (FormatException)
{
- Console.WriteLine("Unable to parse {0}.", timeString);
+ Console.WriteLine($"Unable to parse {timeString}.");
}
timeString = "05/01/2008 8:30 AM";
if (DateTimeOffset.TryParse(timeString, out targetTime))
Console.WriteLine(targetTime);
else
- Console.WriteLine("Unable to parse {0}.", timeString);
+ Console.WriteLine($"Unable to parse {timeString}.");
timeString = "Thursday, 01 May 2008 08:30";
try
@@ -228,7 +225,7 @@ private static void ParseTimeString()
}
catch (FormatException)
{
- Console.WriteLine("Unable to parse {0}.", timeString);
+ Console.WriteLine($"Unable to parse {timeString}.");
}
timeString = "Thursday, 01 May 2008 08:30 +02:00";
@@ -244,7 +241,7 @@ private static void ParseTimeString()
out targetTime))
Console.WriteLine(targetTime);
else
- Console.WriteLine("Unable to parse {0}.", timeString);
+ Console.WriteLine($"Unable to parse {timeString}.");
// The example displays the following output to the console:
// 5/1/2008 8:30:00 AM +01:00
// 5/1/2008 8:30:00 AM -07:00
diff --git a/docs/standard/exceptions/snippets/how-to-use-finally-blocks/csharp/source2.cs b/docs/standard/exceptions/snippets/how-to-use-finally-blocks/csharp/source2.cs
index b73332e7dee12..7e5b659624f6d 100644
--- a/docs/standard/exceptions/snippets/how-to-use-finally-blocks/csharp/source2.cs
+++ b/docs/standard/exceptions/snippets/how-to-use-finally-blocks/csharp/source2.cs
@@ -1,4 +1,4 @@
-//
+//
class ArgumentOutOfRangeExample
{
public static void Main()
@@ -12,7 +12,7 @@ public static void Main()
}
catch (ArgumentOutOfRangeException e)
{
- Console.WriteLine("Error: {0}", e);
+ Console.WriteLine($"Error: {e}");
throw;
}
finally
diff --git a/docs/standard/io/snippets/how-to-use-named-pipes-for-network-interprocess-communication/csharp/NamedPipeServerStream_ImpersonationSample/Program.cs b/docs/standard/io/snippets/how-to-use-named-pipes-for-network-interprocess-communication/csharp/NamedPipeServerStream_ImpersonationSample/Program.cs
index b8826451ae56e..a5a5c22fb5eeb 100644
--- a/docs/standard/io/snippets/how-to-use-named-pipes-for-network-interprocess-communication/csharp/NamedPipeServerStream_ImpersonationSample/Program.cs
+++ b/docs/standard/io/snippets/how-to-use-named-pipes-for-network-interprocess-communication/csharp/NamedPipeServerStream_ImpersonationSample/Program.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.IO;
using System.IO.Pipes;
@@ -30,7 +30,7 @@ public static void Main()
{
if (servers[j]!.Join(250))
{
- Console.WriteLine("Server thread[{0}] finished.", servers[j]!.ManagedThreadId);
+ Console.WriteLine($"Server thread[{servers[j]!.ManagedThreadId}] finished.");
servers[j] = null;
i--; // decrement the thread watch count
}
@@ -50,7 +50,7 @@ private static void ServerThread(object? data)
// Wait for a client to connect
pipeServer.WaitForConnection();
- Console.WriteLine("Client connected on thread[{0}].", threadId);
+ Console.WriteLine($"Client connected on thread[{threadId}].");
try
{
//
@@ -78,7 +78,7 @@ private static void ServerThread(object? data)
// or disconnected.
catch (IOException e)
{
- Console.WriteLine("ERROR: {0}", e.Message);
+ Console.WriteLine($"ERROR: {e.Message}");
}
pipeServer.Close();
}
diff --git a/docs/standard/parallel-programming/snippets/cs/asyncculture1.cs b/docs/standard/parallel-programming/snippets/cs/asyncculture1.cs
index 1880ac7cc3f95..18b9fdf482cab 100644
--- a/docs/standard/parallel-programming/snippets/cs/asyncculture1.cs
+++ b/docs/standard/parallel-programming/snippets/cs/asyncculture1.cs
@@ -1,4 +1,4 @@
-//
+//
using System;
using System.Globalization;
using System.Threading;
@@ -20,18 +20,15 @@ public static void Main()
return output;
};
- Console.WriteLine("The example is running on thread {0}",
- Thread.CurrentThread.ManagedThreadId);
+ Console.WriteLine($"The example is running on thread {Thread.CurrentThread.ManagedThreadId}");
// Make the current culture different from the system culture.
- Console.WriteLine("The current culture is {0}",
- CultureInfo.CurrentCulture.Name);
+ Console.WriteLine($"The current culture is {CultureInfo.CurrentCulture.Name}");
if (CultureInfo.CurrentCulture.Name == "fr-FR")
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
else
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
- Console.WriteLine("Changed the current culture to {0}.\n",
- CultureInfo.CurrentCulture.Name);
+ Console.WriteLine($"Changed the current culture to {CultureInfo.CurrentCulture.Name}.\n");
// Execute the delegate synchronously.
Console.WriteLine("Executing the delegate synchronously:");
diff --git a/docs/standard/parallel-programming/snippets/cs/cancellation1.cs b/docs/standard/parallel-programming/snippets/cs/cancellation1.cs
index bf2807a659d93..4b17d39abb60c 100644
--- a/docs/standard/parallel-programming/snippets/cs/cancellation1.cs
+++ b/docs/standard/parallel-programming/snippets/cs/cancellation1.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -78,8 +78,8 @@ public static async Task Main()
Console.WriteLine(ex.Message);
}
- Console.WriteLine("\nAntecedent Status: {0}", task.Status);
- Console.WriteLine("Continuation Status: {0}", continuation.Status);
+ Console.WriteLine($"\nAntecedent Status: {task.Status}");
+ Console.WriteLine($"Continuation Status: {continuation.Status}");
}
static void Elapsed(object? state)