Encoding.Equals Method (Object)
Assembly: mscorlib (in mscorlib.dll)
Two instances of Encoding are considered equal if they correspond to the same code page and their EncoderFallback and DecoderFallback objects are equal. In particular, derived code pages all have a code page of 0 and their fallbacks are normally a null reference (Nothing in Visual Basic)(Nothing in Visual Basic .NET). Thus they are all considered equal to one another. One consequence is that when Equals is used to populate a hash table, all derived encodings compare equal and fall into the same hash table slot.
The following code example gets two instances of the same encoding (one by codepage and another by name), and checks their equality.
using namespace System; using namespace System::Text; int main() { // Get a UTF-32 encoding by codepage. Encoding^ e1 = Encoding::GetEncoding( 65005 ); // Get a UTF-32 encoding by name. Encoding^ e2 = Encoding::GetEncoding( "utf-32" ); // Check their equality. Console::WriteLine( "e1 equals e2? {0}", e1->Equals( e2 ) ); } /* This code produces the following output. e1 equals e2? True */
import System.*;
import System.Text.*;
public class SamplesEncoding
{
public static void main(String[] args)
{
// Get a UTF-32 encoding by codepage.
Encoding e1 = Encoding.GetEncoding(65005);
// Get a UTF-32 encoding by name.
Encoding e2 = Encoding.GetEncoding("utf-32");
// Check their equality.
Console.WriteLine("e1 equals e2? {0}",
System.Convert.ToString(e1.Equals(e2)));
} //main
} //SamplesEncoding
/*
This code produces the following output.
e1 equals e2? True
*/
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.