Skip to content

Commit ec4f911

Browse files
Changed String to string. IDE0049 (dotnet#10384)
1 parent dc266af commit ec4f911

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//Example1.Main();
2+
//Example2.Main();
3+
//Example3.Main();
4+
Example4.Main();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

snippets/csharp/System/String/Replace/replace1.cs

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

3-
public class Example
3+
public class Example1
44
{
55
public static void Main()
66
{
77
// <Snippet1>
8-
String s = "aaa";
9-
Console.WriteLine("The initial string: '{0}'", s);
8+
string s = "aaa";
9+
Console.WriteLine($"The initial string: '{s}'");
1010
s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d");
11-
Console.WriteLine("The final string: '{0}'", s);
11+
Console.WriteLine($"The final string: '{s}'");
1212

1313
// The example displays the following output:
1414
// The initial string: 'aaa'

snippets/csharp/System/String/Replace/replace2.cs

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

3-
public class Example
3+
public class Example2
44
{
55
public static void Main()
66
{
77
// <Snippet2>
8-
String s = new String('a', 3);
9-
Console.WriteLine("The initial string: '{0}'", s);
8+
string s = new('a', 3);
9+
Console.WriteLine($"The initial string: '{s}'");
1010
s = s.Replace('a', 'b').Replace('b', 'c').Replace('c', 'd');
11-
Console.WriteLine("The final string: '{0}'", s);
11+
Console.WriteLine($"The final string: '{s}'");
1212

1313
// The example displays the following output:
1414
// The initial string: 'aaa'

snippets/csharp/System/String/Replace/string.replace1.cs

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

3-
class stringReplace1 {
4-
public static void Main() {
3+
class Example3
4+
{
5+
public static void Main()
6+
{
57
//<snippet1>
6-
String str = "1 2 3 4 5 6 7 8 9";
7-
Console.WriteLine("Original string: \"{0}\"", str);
8-
Console.WriteLine("CSV string: \"{0}\"", str.Replace(' ', ','));
8+
string str = "1 2 3 4 5 6 7 8 9";
9+
Console.WriteLine($"Original string: \"{str}\"");
10+
Console.WriteLine($"CSV string: \"{str.Replace(' ', ',')}\"");
911

1012
// This example produces the following output:
1113
// Original string: "1 2 3 4 5 6 7 8 9"

snippets/csharp/System/String/Replace/stringreplace.cs

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

3-
public class ReplaceTest
3+
public class Example4
44
{
55
public static void Main()
66
{
7-
87
//<snippet1>
98
string errString = "This docment uses 3 other docments to docment the docmentation";
109

11-
Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString);
10+
Console.WriteLine($"The original string is:{Environment.NewLine}'{errString}'{Environment.NewLine}");
1211

1312
// Correct the spelling of "document".
14-
1513
string correctString = errString.Replace("docment", "document");
1614

17-
Console.WriteLine("After correcting the string, the result is:{0}'{1}'",
18-
Environment.NewLine, correctString);
15+
Console.WriteLine($"After correcting the string, the result is:{Environment.NewLine}'{correctString}'");
1916

2017
// This code example produces the following output:
2118
//

0 commit comments

Comments
 (0)