This documentation is archived and is not being maintained.
String::Equals Method (Object)
Visual Studio 2008
Updated: February 2009
Namespace:
System
Assembly: mscorlib (in mscorlib.dll)
Parameters
- obj
- Type: System::Object
An Object.
Return Value
Type: System::Booleantrue if obj is a String and its value is the same as this instance; otherwise, false.
The following example demonstrates the Equals method.
// Sample for String::Equals(Object) // String::Equals(String) // String::Equals(String, String) using namespace System; using namespace System::Text; int main() { StringBuilder^ sb = gcnew StringBuilder( "abcd" ); String^ str1 = "abcd"; String^ str2 = nullptr; Object^ o2 = nullptr; Console::WriteLine(); Console::WriteLine( " * The value of String str1 is '{0}'.", str1 ); Console::WriteLine( " * The value of StringBuilder sb is '{0}'.", sb ); Console::WriteLine(); Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder, not a String." ); Console::WriteLine( " Is str1 equal to sb?: {0}", str1->Equals( sb ) ); Console::WriteLine(); Console::WriteLine( "1b) String::Equals(Object). Object is a String." ); str2 = sb->ToString(); o2 = str2; Console::WriteLine( " * The value of Object o2 is '{0}'.", o2 ); Console::WriteLine( " Is str1 equal to o2?: {0}", str1->Equals( o2 ) ); Console::WriteLine(); Console::WriteLine( " 2) String::Equals(String)" ); Console::WriteLine( " * The value of String str2 is '{0}'.", str2 ); Console::WriteLine( " Is str1 equal to str2?: {0}", str1->Equals( str2 ) ); Console::WriteLine(); Console::WriteLine( " 3) String::Equals(String, String)" ); Console::WriteLine( " Is str1 equal to str2?: {0}", String::Equals( str1, str2 ) ); } /* This example produces the following results: * The value of String str1 is 'abcd'. * The value of StringBuilder sb is 'abcd'. 1a) String::Equals(Object). Object is a StringBuilder, not a String. Is str1 equal to sb?: False 1b) String::Equals(Object). Object is a String. * The value of Object o2 is 'abcd'. Is str1 equal to o2?: True 2) String::Equals(String) * The value of String str2 is 'abcd'. Is str1 equal to str2?: True 3) String::Equals(String, String) Is str1 equal to str2?: True */
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: