Partager via


IntPtr Structure

Microsoft Silverlight will reach end of support after October 2021. Learn more.

A platform-specific type that is used to represent a pointer or a handle.

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Structure IntPtr
[ComVisibleAttribute(true)]
public struct IntPtr

The IntPtr type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IntPtr(Int32) Initializes a new instance of IntPtr using the specified 32-bit pointer or handle.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IntPtr(Int64) Initializes a new instance of IntPtr using the specified 64-bit pointer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IntPtr(Void*) Initializes a new instance of IntPtr using the specified pointer to an unspecified type.

Top

Properties

  Name Description
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Size Gets the size of this instance.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Returns a value indicating whether this instance is equal to a specified object. (Overrides ValueType.Equals(Object).)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Returns the hash code for this instance. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToInt32 Converts the value of this instance to a 32-bit signed integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToInt64 Converts the value of this instance to a 64-bit signed integer.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToPointer Converts the value of this instance to a pointer to an unspecified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Converts the numeric value of the current IntPtr object to its equivalent string representation. (Overrides ValueType.ToString().)

Top

Operators

  Name Description
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equality Determines whether two specified instances of IntPtr are equal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(Int32 to IntPtr) Converts the value of a 32-bit signed integer to an IntPtr.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(Int64 to IntPtr) Converts the value of a 64-bit signed integer to an IntPtr.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(IntPtr to Void*) Converts the value of the specified IntPtr to a pointer to an unspecified type.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(IntPtr to Int64) Converts the value of the specified IntPtr to a 64-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(IntPtr to Int32) Converts the value of the specified IntPtr to a 32-bit signed integer.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Explicit(Void* to IntPtr) Converts the specified pointer to an unspecified type to an IntPtr.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Inequality Determines whether two specified instances of IntPtr are not equal.

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Zero A read-only field that represents a pointer or handle that has been initialized to zero.

Top

Remarks

The IntPtr type is designed to be an integer whose size is platform-specific. That is, an instance of this type is expected to be 32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit hardware and operating systems.

The IntPtr type can be used by languages that support pointers, and as a common means of referring to data between languages that do and do not support pointers.

IntPtr objects can also be used to hold handles. For example, instances of IntPtr are used extensively in the System.IO.FileStream class to hold file handles.

The IntPtr type is CLS-compliant, while the UIntPtr type is not. Only the IntPtr type is used in the common language runtime. The UIntPtr type is provided mostly to maintain architectural symmetry with the IntPtr type.

Version Information

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

Platforms

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

Thread Safety

This type is thread safe.

See Also

Reference