SPContentTypeId.Equals Method

Determines whether the current SPContentTypeId object is equal to another object (possibly of unknown type).

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Overrides Function Equals ( _
    o As Object _
) As Boolean
'Usage
Dim instance As SPContentTypeId
Dim o As Object
Dim returnValue As Boolean

returnValue = instance.Equals(o)
public override bool Equals(
    Object o
)

Parameters

  • o
    Type: System.Object

    An object to compare with the current content type ID.

Return Value

Type: System.Boolean
true if the current object is equal to the object that was passed as an argument; otherwise, false.

Remarks

This method returns false if the argument is an object of type SPContentTypeId but has a value that is not equal to the value of the current SPContentTypeId object. This method returns true if the two objects are of equal value. This behavior is illustrated by the following code.

SPContentTypeId x = SPBuiltInContentTypeId.Item;
SPContentTypeId y = SPBuiltInContentTypeId.Document;

Console.WriteLine(x.Equals(y)); // false
x = y;
Console.WriteLine(x.Equals(y)); // true
Dim x As SPContentTypeId = SPBuiltInContentTypeId.Item
Dim y As SPContentTypeId = SPBuiltInContentTypeId.Document

Console.WriteLine(x.Equals(y)) ' false
x = y
Console.WriteLine(x.Equals(y)) ' true

The SPContentTypeId.Equals(System.Object) method also returns false if the argument is a null reference (Nothing in Visual Basic) or not an object of type SPContentTypeId. This is different from the behavior of the CompareTo method, which requires an argument of type SPContentTypeId. Differences between the two methods are illustrated by the following code.

SPContentTypeId x = SPBuiltInContentTypeId.Item;
System.Object y = x;

Console.WriteLine(x.Equals(x));    // true.
Console.WriteLine(x.Equals(y));    // true.
Console.WriteLine(x.Equals(null)); // false.

Console.WriteLine(x.CompareTo(x) == 0); // true.
Console.WriteLine(x.CompareTo((SPContentTypeId)y) == 0); // true.

Console.WriteLine(x.CompareTo(y) == 0); // Does not compile.
Console.WriteLine(x.CompareTo(null) == 0);  // Does not compile.
Dim x As SPContentTypeId = SPBuiltInContentTypeId.Item
Dim y As System.Object = x

Console.WriteLine(x.Equals(x)) ' true.
Console.WriteLine(x.Equals(y)) ' true.
Console.WriteLine(x.Equals(Nothing)) ' false.

Console.WriteLine(x.CompareTo(x) = 0) ' true.
Console.WriteLine(x.CompareTo(CType(y, SPContentTypeId)) = 0) ' true.

Console.WriteLine(x.CompareTo(y) = 0) ' Does not compile.
Console.WriteLine(x.CompareTo(Nothing) = 0) ' Does not compile.

See Also

Reference

SPContentTypeId Structure

SPContentTypeId Members

Microsoft.SharePoint Namespace

Equality

CompareTo

Other Resources

Content Type IDs

Base Content Type Hierarchy