Redigera

Dela via


Platform::Object Class

Provides common behavior for ref classes and ref structs in Windows Runtime apps. All ref class and ref struct instances are implicitly convertible to Platform::Object^ and can override its virtual ToString method.

Syntax

public ref class Object : Object

Members

Public Constructors

Name Description
Object::Object Initializes a new instance of the Object class.

Public Methods

Name Description
Object::Equals Determines whether the specified object is equal to the current object.
Object::GetHashCode Returns the hash code for this instance.
Object::ReferenceEquals Determines whether the specified Object instances are the same instance.
ToString Returns a string that represents the current object. Can be overridden.
GetType Gets a Platform::Type that describes the current instance.

Inheritance Hierarchy

Object

Object

Requirements

Header: vccorlib.h

Namespace: Platform

Object::Equals Method

Determines whether the specified object is equal to the current object.

Syntax

bool Equals(
    Object^ obj
)

Parameters

obj
The object to compare.

Return Value

true if the objects are equal, otherwise false.

Object::GetHashCode Method

Returns the IUnknown* identity value for this instance if it is a COM object, or a computed hash value if it is not a COM object.

Syntax

public:int GetHashCode();

Return Value

A numeric value that uniquely identifies this object.

Remarks

You can use GetHashCode to create keys for objects in maps. You can compare hash codes by using Object::Equals. If the code path is extremely critical and GetHashCode and Equals are not sufficiently fast, then you can drop down to the underlying COM layer and do native IUnknown pointer comparisons.

Object::GetType Method

Returns a Platform::Type object that describes the runtime type of an object.

Syntax

Object::GetType();

Property Value/Return Value

A Platform::Type object that describes the runtime type of the object.

Remarks

The static Type::GetTypeCode can be used to get a Platform::TypeCode Enumeration value that represents the current type. This is mostly useful for built-in types. The type code for any ref class besides Platform::String is Object (1).

The Windows::UI::Xaml::Interop::TypeName class is used in the Windows APIs as a language-independent way of passing type information between Windows components and apps. The Platform::Type Class has operators for converting between Type and TypeName.

Use the typeid operator to return a Platform::Type object for a class name, for example when navigating between XAML pages:

rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments);

Object::Object Constructor

Initializes a new instance of the Object class.

Syntax

public:Object();

Object::ReferenceEquals Method

Determines whether the specified Object instances are the same instance.

Syntax

public:static bool ReferenceEquals(  Object^ obj1,   Object^ obj2);

Parameters

obj1
The first object to compare.

obj2
The second object to compare.

Return Value

true if the two objects are the same; otherwise, false.

Object::ToString Method (C++/CX)

Returns a string that represents the current object.

Syntax

public:
virtual String^ ToString();

Return Value

A string that represents the current object. You can override this method to provide a custom string message in your ref class or struct:

public ref class Tree sealed
{
public:
    Tree(){}
    virtual Platform::String^ ToString() override
    {
      return "I'm a Tree";
    };
};

See also

Platform Namespace
Platform::Type Class
Type System