Skip to content

Commit ed73218

Browse files
authored
add project file (#7887)
1 parent ba7f812 commit ed73218

File tree

5 files changed

+101
-86
lines changed

5 files changed

+101
-86
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFrameworks>net6.0</TargetFrameworks>
6+
7+
</PropertyGroup>
8+
9+
</Project>

snippets/csharp/System/String/Equals/equals.cs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,38 @@
55
using System;
66
using System.Text;
77

8-
class Sample {
9-
public static void Main() {
10-
StringBuilder sb = new StringBuilder("abcd");
11-
String str1 = "abcd";
12-
String str2 = null;
13-
Object o2 = null;
14-
15-
Console.WriteLine();
16-
Console.WriteLine(" * The value of String str1 is '{0}'.", str1);
17-
Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString());
18-
19-
Console.WriteLine();
20-
Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String.");
21-
Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb));
22-
23-
Console.WriteLine();
24-
Console.WriteLine("1b) String.Equals(Object). Object is a String.");
25-
str2 = sb.ToString();
26-
o2 = str2;
27-
Console.WriteLine(" * The value of Object o2 is '{0}'.", o2);
28-
Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2));
29-
30-
Console.WriteLine();
31-
Console.WriteLine(" 2) String.Equals(String)");
32-
Console.WriteLine(" * The value of String str2 is '{0}'.", str2);
33-
Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2));
34-
35-
Console.WriteLine();
36-
Console.WriteLine(" 3) String.Equals(String, String)");
37-
Console.WriteLine(" Is str1 equal to str2?: {0}", String.Equals(str1, str2));
8+
class Sample1
9+
{
10+
public static void Main()
11+
{
12+
StringBuilder sb = new StringBuilder("abcd");
13+
String str1 = "abcd";
14+
String str2 = null;
15+
Object o2 = null;
16+
17+
Console.WriteLine();
18+
Console.WriteLine(" * The value of String str1 is '{0}'.", str1);
19+
Console.WriteLine(" * The value of StringBuilder sb is '{0}'.", sb.ToString());
20+
21+
Console.WriteLine();
22+
Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder, not a String.");
23+
Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb));
24+
25+
Console.WriteLine();
26+
Console.WriteLine("1b) String.Equals(Object). Object is a String.");
27+
str2 = sb.ToString();
28+
o2 = str2;
29+
Console.WriteLine(" * The value of Object o2 is '{0}'.", o2);
30+
Console.WriteLine(" Is str1 equal to o2?: {0}", str1.Equals(o2));
31+
32+
Console.WriteLine();
33+
Console.WriteLine(" 2) String.Equals(String)");
34+
Console.WriteLine(" * The value of String str2 is '{0}'.", str2);
35+
Console.WriteLine(" Is str1 equal to str2?: {0}", str1.Equals(str2));
36+
37+
Console.WriteLine();
38+
Console.WriteLine(" 3) String.Equals(String, String)");
39+
Console.WriteLine(" Is str1 equal to str2?: {0}", String.Equals(str1, str2));
3840
}
3941
}
4042
/*
@@ -57,4 +59,4 @@ public static void Main() {
5759
3) String.Equals(String, String)
5860
Is str1 equal to str2?: True
5961
*/
60-
//</snippet1>
62+
//</snippet1>

snippets/csharp/System/String/Equals/equals_ex3.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@
33
using System.Globalization;
44
using System.Threading;
55

6-
public class Example
6+
public class Example3
77
{
8-
public static void Main()
9-
{
10-
String[] cultureNames = { "en-US", "se-SE" };
11-
String[] strings1 = { "case", "encyclopædia",
8+
public static void Main()
9+
{
10+
String[] cultureNames = { "en-US", "se-SE" };
11+
String[] strings1 = { "case", "encyclopædia",
1212
"encyclopædia", "Archæology" };
13-
String[] strings2 = { "Case", "encyclopaedia",
13+
String[] strings2 = { "Case", "encyclopaedia",
1414
"encyclopedia" , "ARCHÆOLOGY" };
15-
StringComparison[] comparisons = (StringComparison[]) Enum.GetValues(typeof(StringComparison));
16-
17-
foreach (var cultureName in cultureNames) {
18-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
19-
Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
20-
for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++) {
21-
foreach (var comparison in comparisons)
22-
Console.WriteLine(" {0} = {1} ({2}): {3}", strings1[ctr],
23-
strings2[ctr], comparison,
24-
String.Equals(strings1[ctr], strings2[ctr], comparison));
15+
StringComparison[] comparisons = (StringComparison[])Enum.GetValues(typeof(StringComparison));
2516

26-
Console.WriteLine();
27-
}
28-
Console.WriteLine();
29-
}
30-
}
17+
foreach (var cultureName in cultureNames)
18+
{
19+
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
20+
Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
21+
for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++)
22+
{
23+
foreach (var comparison in comparisons)
24+
Console.WriteLine(" {0} = {1} ({2}): {3}", strings1[ctr],
25+
strings2[ctr], comparison,
26+
String.Equals(strings1[ctr], strings2[ctr], comparison));
27+
28+
Console.WriteLine();
29+
}
30+
Console.WriteLine();
31+
}
32+
}
3133
}
3234
// The example displays the following output:
3335
// Current Culture: en-US

snippets/csharp/System/String/Equals/equals_ex4.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@
33
using System.Globalization;
44
using System.Threading;
55

6-
public class Example
6+
public class Example4
77
{
8-
public static void Main()
9-
{
10-
String[] cultureNames = { "en-US", "se-SE" };
11-
String[] strings1 = { "case", "encyclopædia",
8+
public static void Main()
9+
{
10+
String[] cultureNames = { "en-US", "se-SE" };
11+
String[] strings1 = { "case", "encyclopædia",
1212
"encyclopædia", "Archæology" };
13-
String[] strings2 = { "Case", "encyclopaedia",
13+
String[] strings2 = { "Case", "encyclopaedia",
1414
"encyclopedia" , "ARCHÆOLOGY" };
15-
StringComparison[] comparisons = (StringComparison[]) Enum.GetValues(typeof(StringComparison));
16-
17-
foreach (var cultureName in cultureNames) {
18-
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
19-
Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
20-
for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++) {
21-
foreach (var comparison in comparisons)
22-
Console.WriteLine(" {0} = {1} ({2}): {3}", strings1[ctr],
23-
strings2[ctr], comparison,
24-
strings1[ctr].Equals(strings2[ctr], comparison));
15+
StringComparison[] comparisons = (StringComparison[])Enum.GetValues(typeof(StringComparison));
2516

26-
Console.WriteLine();
27-
}
28-
Console.WriteLine();
29-
}
30-
}
17+
foreach (var cultureName in cultureNames)
18+
{
19+
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureName);
20+
Console.WriteLine("Current Culture: {0}", CultureInfo.CurrentCulture.Name);
21+
for (int ctr = 0; ctr <= strings1.GetUpperBound(0); ctr++)
22+
{
23+
foreach (var comparison in comparisons)
24+
Console.WriteLine(" {0} = {1} ({2}): {3}", strings1[ctr],
25+
strings2[ctr], comparison,
26+
strings1[ctr].Equals(strings2[ctr], comparison));
27+
28+
Console.WriteLine();
29+
}
30+
Console.WriteLine();
31+
}
32+
}
3133
}
3234
// The example displays the following output:
3335
// Current Culture: en-US

snippets/csharp/System/String/Equals/equalsex1.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
public class Example
55
{
6-
public static void Main()
7-
{
8-
Console.OutputEncoding = System.Text.Encoding.UTF8;
9-
string word = "File";
10-
string[] others = { word.ToLower(), word, word.ToUpper(), "Fıle" };
11-
foreach (string other in others)
12-
{
13-
if (word.Equals(other))
14-
Console.WriteLine("{0} = {1}", word, other);
15-
else
16-
Console.WriteLine("{0} {1} {2}", word, '\u2260', other);
17-
}
18-
}
6+
public static void Main()
7+
{
8+
Console.OutputEncoding = System.Text.Encoding.UTF8;
9+
string word = "File";
10+
string[] others = { word.ToLower(), word, word.ToUpper(), "Fıle" };
11+
foreach (string other in others)
12+
{
13+
if (word.Equals(other))
14+
Console.WriteLine("{0} = {1}", word, other);
15+
else
16+
Console.WriteLine("{0} {1} {2}", word, '\u2260', other);
17+
}
18+
}
1919
}
2020
// The example displays the following output:
2121
// File ≠ file

0 commit comments

Comments
 (0)