Strings

String Compare in C#

Used to check equality of two strings.


Syntax
bool equal = stringName.Equals("String literal"); //returns true or false
///static method
bool equal = String.Equals(string1, string2);
//using conditional operator
bool isEqual = string1 == string2;

Notes

The method of comparison can be optionally passed into the Equals method. For example, StringComparison.OrdinalIgnoreCase will ignore casing.


Example
string password = "Open Sesame"
if(password.equals("Open Sesame") {
    Console.WriteLine("The door has open.");
} else {
    Console.WriteLine("The door has stayed shut.");
}

< String Length   |   String Trim >

© 2018 SyntaxDB. All Rights Reserved.