C# String Equals(String, String)

Description

String Equals(String, String) determines whether two specified String objects have the same value.

Syntax

String.Equals(String, String) has the following syntax.


public static bool Equals(
  string a,
  string b
)

Parameters

String.Equals(String, String) has the following parameters.

  • a - The first string to compare, or null.
  • b - The second string to compare, or null.

Returns

String.Equals(String, String) method returns true if the value of a is the same as the value of b; otherwise, false. If both a and b are null, the method returns true.

Example

The following code shows how to use String.Equals(String, String) method.


/* ww w  .ja v a2  s  .  co m*/
using System;
using System.Text;

class Sample {
    public static void Main() {
        String      str1 = "abcd";
        String      str2 = null;
    
        Console.WriteLine(String.Equals(str1, str2));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version