System.IntPtr Structure

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

See Also: IntPtr

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public struct IntPtr : ISerializable

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 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.

This type implements the ISerializable interface.

Thread Safety

This type is safe for multithreaded operations.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0

The members of System.IntPtr are listed below.

See Also: ValueType

Public Constructors

Initializes a new instance of IntPtr using the specified 32-bit pointer or handle.

Initializes a new instance of IntPtr using the specified 64-bit pointer.

Initializes a new instance of IntPtr using the specified pointer to an unspecified type.

Public Fields

static readonly
ZeroIntPtr (0).

A read-only field that represents a pointer or handle that has been initialized to zero.

Public Properties

[read-only]
static
SizeInt32 (4).

Gets the size of this instance.

Public Methods

static
Add(IntPtr, Int32) : IntPtr

Adds an offset to the value of a pointer.

override
Equals(Object) : Boolean

Returns a value indicating whether this instance is equal to a specified object.

override
GetHashCode() : Int32

Returns the hash code for this instance.

static
Subtract(IntPtr, Int32) : IntPtr

Subtracts an offset from the value of a pointer.

ToInt32() : Int32

Converts the value of this instance to a 32-bit signed integer.

ToInt64() : Int64

Converts the value of this instance to a 64-bit signed integer.

ToPointer() : Void*

Converts the value of this instance to a pointer to an unspecified type.

override
ToString() : String

Converts the numeric value of the current IntPtr object to its equivalent string representation.

ToString(String) : String

Converts the numeric value of the current IntPtr object to its equivalent string representation.

Public Operators

static
Addition(IntPtr, Int32)

Adds an offset to the value of a pointer.

static
Equality(IntPtr, IntPtr)

Determines whether two specified instances of IntPtr are equal.

static
Inequality(IntPtr, IntPtr)

Determines whether two specified instances of IntPtr are not equal.

static
Subtraction(IntPtr, Int32)

Subtracts an offset from the value of a pointer.

static
Conversion to System.IntPtr(Explicit)
static
Conversion to System.IntPtr(Explicit)
static
Conversion to System.Int32(Explicit)
static
Conversion to System.Int64(Explicit)
static
Conversion to System.Void*(Explicit)
static
Conversion to System.IntPtr(Explicit)

Explicitly Implemented Interface Members

IntPtr$ISerializable.GetObjectData(SerializationInfo,StreamingContext)

Populates a SerializationInfo object with the data needed to serialize the current IntPtr object.