diff --git a/snippets/csharp/System/String/Replace/Program.cs b/snippets/csharp/System/String/Replace/Program.cs
new file mode 100644
index 00000000000..83c629bb8a5
--- /dev/null
+++ b/snippets/csharp/System/String/Replace/Program.cs
@@ -0,0 +1,4 @@
+//Example1.Main();
+//Example2.Main();
+//Example3.Main();
+Example4.Main();
diff --git a/snippets/csharp/System/String/Replace/Project.csproj b/snippets/csharp/System/String/Replace/Project.csproj
new file mode 100644
index 00000000000..24f58ecd991
--- /dev/null
+++ b/snippets/csharp/System/String/Replace/Project.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net8.0
+
+
+
\ No newline at end of file
diff --git a/snippets/csharp/System/String/Replace/replace1.cs b/snippets/csharp/System/String/Replace/replace1.cs
index 847d347b7d1..e51d5798fb7 100644
--- a/snippets/csharp/System/String/Replace/replace1.cs
+++ b/snippets/csharp/System/String/Replace/replace1.cs
@@ -1,14 +1,14 @@
using System;
-public class Example
+public class Example1
{
public static void Main()
{
//
- String s = "aaa";
- Console.WriteLine("The initial string: '{0}'", s);
+ string s = "aaa";
+ Console.WriteLine($"The initial string: '{s}'");
s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d");
- Console.WriteLine("The final string: '{0}'", s);
+ Console.WriteLine($"The final string: '{s}'");
// The example displays the following output:
// The initial string: 'aaa'
diff --git a/snippets/csharp/System/String/Replace/replace2.cs b/snippets/csharp/System/String/Replace/replace2.cs
index e7f77c54ca9..fa88b768e18 100644
--- a/snippets/csharp/System/String/Replace/replace2.cs
+++ b/snippets/csharp/System/String/Replace/replace2.cs
@@ -1,14 +1,14 @@
using System;
-public class Example
+public class Example2
{
public static void Main()
{
//
- String s = new String('a', 3);
- Console.WriteLine("The initial string: '{0}'", s);
+ string s = new('a', 3);
+ Console.WriteLine($"The initial string: '{s}'");
s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd');
- Console.WriteLine("The final string: '{0}'", s);
+ Console.WriteLine($"The final string: '{s}'");
// The example displays the following output:
// The initial string: 'aaa'
diff --git a/snippets/csharp/System/String/Replace/string.replace1.cs b/snippets/csharp/System/String/Replace/string.replace1.cs
index 5164f6da247..ae9f96e60d3 100644
--- a/snippets/csharp/System/String/Replace/string.replace1.cs
+++ b/snippets/csharp/System/String/Replace/string.replace1.cs
@@ -1,11 +1,13 @@
using System;
-class stringReplace1 {
- public static void Main() {
+class Example3
+{
+ public static void Main()
+ {
//
- String str = "1 2 3 4 5 6 7 8 9";
- Console.WriteLine("Original string: \"{0}\"", str);
- Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ','));
+ string str = "1 2 3 4 5 6 7 8 9";
+ Console.WriteLine($"Original string: \"{str}\"");
+ Console.WriteLine($"CSV string: \"{str.Replace(' ', ',')}\"");
// This example produces the following output:
// Original string: "1 2 3 4 5 6 7 8 9"
diff --git a/snippets/csharp/System/String/Replace/stringreplace.cs b/snippets/csharp/System/String/Replace/stringreplace.cs
index 8b74b18173a..118ac67fe7b 100644
--- a/snippets/csharp/System/String/Replace/stringreplace.cs
+++ b/snippets/csharp/System/String/Replace/stringreplace.cs
@@ -1,21 +1,18 @@
using System;
-public class ReplaceTest
+public class Example4
{
public static void Main()
{
-
//
string errString = "This docment uses 3 other docments to docment the docmentation";
- Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString);
+ Console.WriteLine($"The original string is:{Environment.NewLine}'{errString}'{Environment.NewLine}");
// Correct the spelling of "document".
-
string correctString = errString.Replace("docment", "document");
- Console.WriteLine("After correcting the string, the result is:{0}'{1}'",
- Environment.NewLine, correctString);
+ Console.WriteLine($"After correcting the string, the result is:{Environment.NewLine}'{correctString}'");
// This code example produces the following output:
//