Export (0) Print
Expand All

Encoding.Equals Method

Determines whether the specified Object is equal to the current instance.

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)

public override bool Equals(
	Object value
)

Parameters

value
Type: System.Object
The Object to compare with the current instance.

Return Value

Type: System.Boolean
true if value is an instance of Encoding and is equal to the current instance; otherwise, false.

The following example determines whether several Encoding objects are equal.


using System;
using System.Text;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get a UTF-16 encoding.
      Encoding e16_1 = Encoding.GetEncoding("utf-16");

      // Instantiate a second UTF-16 encoding.
      Encoding e16_2 = new UnicodeEncoding();

      // Instantiate a Unicode little endian encoding.
      Encoding le = new UnicodeEncoding(false, true);

      // Instantiate a Unicode big endian encoding.
      Encoding be = new UnicodeEncoding(true, true);

      // Get a UTF-8 encoding by name.
      Encoding e8 = Encoding.GetEncoding("utf-8");

      // Check equality of e16_1 and e16_2.
      outputBlock.Text += String.Format("{0} equals {1}? {2}\n", 
                                        e16_1.WebName, e16_2.WebName, 
                                        e16_1.Equals(e16_2));

      // Check equality of e16_1 and unicode little endian encoding.
      outputBlock.Text += String.Format("{0} equals {1}? {2}\n", 
                                        e16_1.WebName, le.WebName, 
                                        e16_1.Equals(le));

      // Check equality of e16_1 and unicode bug endian encoding.
      outputBlock.Text += String.Format("{0} equals {1}? {2}\n", 
                                        e16_1.WebName, be.WebName, 
                                        e16_1.Equals(be));

      // Check equality of e16_1 and e8.
      outputBlock.Text += String.Format("{0} equals {1}? {2}\n", 
                                        e16_1.WebName, e8.WebName, 
                                        e16_1.Equals(e8));
   }

}


/* 
This example produces the following output:
   utf-16 equals utf-16? True
   utf-16 equals utf-16? True
   utf-16 equals utf16BE? False
   utf-16 equals utf8? False
*/



Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft