System.IntPtr Structure

public struct IntPtr

Base Types

Object
  ValueType
    IntPtr

Assembly

mscorlib

Library

RuntimeInfrastructure

Summary

An implementation-specific type that is used to represent a pointer or a handle.

Description

The IntPtr type is designed to be an implementation-sized pointer. An instance of this type is expected to be the size of a native int for the current implementation.

For more information on the native int type, see Partition II of the CLI Specification.

[Note: The IntPtr type provides CLS-compliant pointer functionality.

IntPtr instances can also be used to hold handles.

The IntPtr type is CLS-compliant while the UIntPtr type is not. The UIntPtr type is provided mostly to maintain architectural symmetry with the IntPtr type.

]

See Also

System Namespace

Members

IntPtr Constructors

IntPtr(int) Constructor
IntPtr(long) Constructor

IntPtr Methods

IntPtr.Equals Method
IntPtr.GetHashCode Method
IntPtr.ToInt32 Method
IntPtr.ToInt64 Method
IntPtr.ToPointer Method
IntPtr.ToString Method
IntPtr.op_Equality Method
IntPtr.op_Inequality Method

IntPtr Fields

IntPtr.Zero Field

IntPtr Properties

IntPtr.Size Property


IntPtr(int) Constructor

public IntPtr(int value);

Summary

Constructs a new IntPtr structure using the specified Int32 containing a pointer or a handle.

Parameters

value
A Int32 containing a pointer or a handle.

See Also

System.IntPtr Structure, System Namespace

IntPtr(long) Constructor

public IntPtr(long value);

Summary

Constructs a new IntPtr structure using the specified Int64 containing a pointer or a handle.

Parameters

value
A Int64 containing a pointer or a handle.

Exceptions

Exception TypeCondition
OverflowExceptionThe current platform is a 32-bit platform and the value of the current instance is greater than System.Int32.MaxValue or less than System.Int32.MinValue.

See Also

System.IntPtr Structure, System Namespace

IntPtr.Equals Method

public override bool Equals(object obj);

Summary

Determines whether the current instance and the specified Object represent the same type and value.

Parameters

obj
The Object to compare to the current instance.

Return Value

true if obj is a IntPtr instance and has the same value as the current instance. If obj is a null reference or is not an instance of IntPtr, returns false .

Description

[Note: The method overrides System.Object.Equals(System.Object).]

See Also

System.IntPtr Structure, System Namespace

IntPtr.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Description

[Note: The algorithm used to generate the hash code is unspecified.]

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.IntPtr Structure, System Namespace

IntPtr.ToInt32 Method

public int ToInt32();

Summary

Converts the value of the current instance to a Int32.

Return Value

A Int32 containing the same value as the current instance.

Exceptions

Exception TypeCondition
OverflowExceptionThe current platform is not a 32-bit platform and the value of the current instance is greater than System.Int32.MaxValue or less than System.Int32.MinValue.

See Also

System.IntPtr Structure, System Namespace

IntPtr.ToInt64 Method

public long ToInt64();

Summary

Converts the value of the current instance to a Int64.

Return Value

A Int64 containing the same value as the current instance.

See Also

System.IntPtr Structure, System Namespace

IntPtr.ToPointer Method

unsafe public void* ToPointer();

Summary

Converts the value of the current instance to a pointer to void .

Return Value

A pointer to void .

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.IntPtr.ToInt32.

[Note: A pointer to void points to memory containing data of an unspecified type.]

Attributes

CLSCompliantAttribute(false)

See Also

System.IntPtr Structure, System Namespace

IntPtr.ToString Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance.

Description

[Note: If System.IntPtr.Size for the current instance is 4, System.IntPtr.ToString is equivalent to System.Int32.ToString(); otherwise, this method is equivalent to System.Int64.ToString().

This method overrides System.Object.ToString.

]

See Also

System.IntPtr Structure, System Namespace

IntPtr.op_Equality Method

public static bool operator ==(IntPtr value1, IntPtr value2);

Summary

Determines whether the two specified instances of IntPtr represent the same value.

Parameters

value1
The first IntPtr to compare for equality.
value2
The second IntPtr to compare for equality.

Return Value

true if value1 represents the same value as value2; otherwise, false .

See Also

System.IntPtr Structure, System Namespace

IntPtr.op_Inequality Method

public static bool operator !=(IntPtr value1, IntPtr value2);

Summary

Determines whether the two specified instances of IntPtr represent different values.

Parameters

value1
The first IntPtr to compare for inequality.
value2
The second IntPtr to compare for inequality.

Return Value

true if value1 represents a different value than value2; otherwise, false .

See Also

System.IntPtr Structure, System Namespace

IntPtr.Zero Field

public static readonly IntPtr Zero;

Summary

Represents a pointer or handle that has been initialized as zero.

Description

[Note: The value of this field is not null , but is instead a pointer which has been assigned the value zero. Use this field to efficiently determine whether an instance of IntPtr has been set to a value other than zero. For example, if ip is a IntPtr instance, using ip != IntPtr.Zero is more efficient than ip != new IntPtr(0) to test if ip has been set to a value other than zero.

]

See Also

System.IntPtr Structure, System Namespace

IntPtr.Size Property

public static int Size { get; }

Summary

Gets the size in bytes of a pointer or a handle for the current implementation.

Property Value

A Int32 containing the number of bytes of a pointer or handle for the current implementation. The value of this property is equal to the number of bytes contained by the native int type in the current implementation.

Description

This property is read-only.

For more information on the native int type, see Partition II of the CLI Specification.

See Also

System.IntPtr Structure, System Namespace