GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialspoint.com — C# String - Equals() Method
Selected Reading
C# String - Equals() MethodThe C# String Equals() method is used to check whether two string objects have the same value or not. It compares string values, allowing for case-sensitive or case-insensitive options. SyntaxFollowing is the syntax of the C# string Equals() method − public static bool Equals (string? str1, string? str2); ParametersThis method accepts the following parameters −
Return valueThis method returns Example 1: Compare Two StringsFollowing is the basic example of the Equals() method to check whether the both string is same or not − using System;
class Program {
static void Main() {
string str1 = "Hello, tutorialspoint";
string str2 = "Hello, tutorialspoint";
bool res = string.Equals(str1, str2);
Console.Write(res == true
? "Both strings ar eequal, Yes"
: "Both strings are nor Ewual ");
}
}
OutputFollowing is the output − True Example 2: Case Sensitive ComparisonLet us look another example of the Equals() method to check if the string object is case sensitive then this method retrun true or not − using System;
class Program {
static void Main() {
string str1 = "Hello, tutorialspoint";
string str2 = "hello, Tutorialspoint";
bool res = string.Equals(str1, str2);
Console.WriteLine("Both strings are same? " + res);
}
}
OutputFollowing is the output − Both strings are same? False Example 3: Case Insensitive ComparisonIn this example, we use the Equals() method to perform the case insensitive comparison − using System;
class Program {
static void Main() {
string str1 = "Hello, world";
string str2 = "hello, World";
// Case-insensitive comparison
bool result = str1.Equals(str2, StringComparison.OrdinalIgnoreCase);
Console.WriteLine("Is both strings are equal? " + result);
}
}
OutputFollowing is the output − Is both strings are equal? True csharp_strings.htm
Advertisements
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |