System.UIntPtr Structure

Assembly: Mscorlib.dll
Namespace: System
Summary
A platform-specific type that is used to represent a pointer or a handle.
This class is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
[Serializable]
public struct UIntPtr : ISerializable
Thread Safety
This type is safe for multithreaded operations.
Remarks
The UIntPtr 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 UIntPtr 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. UIntPtr objects can also be used to hold 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.

See also:
System Namespace | IntPtr

System.UIntPtr Member List:

Public Constructors
ctor #1 Overloaded:
.ctor(uint value)

Initializes a new instance of the UIntPtr structure using the specified 32-bit pointer or handle.
ctor #2 Overloaded:
.ctor(ulong value)

Initializes a new instance of UIntPtr using the specified 64-bit pointer or handle.
ctor #3 Overloaded:
.ctor(void* value)

Initializes a new instance of UIntPtr using the specified pointer to an unspecified type.
Public Fields
Zero A read-only field that represents a pointer or handle that has been initialized to zero.
Public Properties
Size Read-only

Gets the size of this instance.
Public Methods
Equals Overridden:
Returns a value indicating whether this instance is equal to a specified object.
GetHashCode Overridden:
Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToPointer Converts the value of this instance to a pointer to an unspecified type.
ToString Overridden:
Converts the numeric value of this instance to its equivalent string representation.
ToUInt32 Converts the value of this instance to a 32-bit unsigned integer.
ToUInt64 Converts the value of this instance to a 64-bit unsigned integer.
Public Operators and Type Conversions
op_Equality Determines whether two specified instances of UIntPtr are equal.
op_Explicit
(convert System.UInt32 to System.UIntPtr)
Overloaded:
op_Explicit(uint value)

Converts the value of a 32-bit unsigned integer to an UIntPtr.
op_Explicit
(convert System.UInt64 to System.UIntPtr)
Overloaded:
op_Explicit(ulong value)

Converts the value of a 64-bit unsigned integer to an UIntPtr.
op_Explicit
(convert System.UIntPtr to System.Void*)
Overloaded:
op_Explicit(UIntPtr value)

Converts the value of the specified UIntPtr to a pointer to an unspecified type.
op_Explicit
(convert System.UIntPtr to System.UInt64)
Overloaded:
op_Explicit(UIntPtr value)

Converts the value of the specified UIntPtr to a 64-bit unsigned integer.
op_Explicit
(convert System.UIntPtr to System.UInt32)
Overloaded:
op_Explicit(UIntPtr value)

Converts the value of the specified UIntPtr to a 32-bit unsigned integer.
op_Explicit
(convert System.Void* to System.UIntPtr)
Overloaded:
op_Explicit(void* value)

Converts the specified pointer to an unspecified type to a UIntPtr.
op_Inequality Determines whether two specified instances of UIntPtr are not equal.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.UIntPtr Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the UIntPtr structure using the specified 32-bit pointer or handle.
This class is not CLS Compliant

C# Syntax:
public UIntPtr(
   uint value
);
Parameters:

value

A pointer or handle contained in a 32-bit unsigned integer.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of UIntPtr using the specified 64-bit pointer or handle.
This class is not CLS Compliant

C# Syntax:
public UIntPtr(
   ulong value
);
Parameters:

value

A pointer or handle contained in a 64-bit unsigned integer.

Exceptions
Exception Type Condition
OverflowException On a 32-bit platform, value is too large to represent as an UIntPtr.
Remarks
An exception is only thrown if the value of value requires more bits than the current platform supports.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of UIntPtr using the specified pointer to an unspecified type.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public UIntPtr(
   void* value
);
Parameters:

value

A pointer to an unspecified type.

See also:
Void

Return to top


Field: Zero
Summary
A read-only field that represents a pointer or handle that has been initialized to zero.
This class is not CLS Compliant

C# Syntax:
public static readonly UIntPtr Zero;
Remarks
The value of this field is not equivalent to null. Use this field to efficiently determine whether an instance of UIntPtr has been set to a value other than zero.

For example, assume the variable, uip, is an instance of UIntPtr. You can determine if it has been set by comparing it to the value returned by a constructor, for example: " if uip != new UIntPtr(0)... ". However, invoking a constructor to get an unintialized pointer is inefficient. It is better to code either " if uip != UIntPtr.Zero... ", or " if !UIntPtr.Zero.Equals(uip)... ".

Return to top


Property: Size (read-only)
Summary
Gets the size of this instance.
This class is not CLS Compliant

C# Syntax:
public static int Size {get;}

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Returns a value indicating whether this instance is equal to a specified object.
This class is not CLS Compliant

C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An object to compare with this instance or null.

Return Value:
true if obj is an instance of UIntPtr and equals the value of this instance; otherwise, false.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
This class is not CLS Compliant

C# Syntax:
~UIntPtr();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
This class is not CLS Compliant

C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
This class is not CLS Compliant

C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
This class is not CLS Compliant

C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: op_Equality(
   UIntPtr value1,
   UIntPtr value2
)
Summary
Determines whether two specified instances of UIntPtr are equal.
This class is not CLS Compliant

C# Syntax:
public static bool operator ==(
   UIntPtr value1,
   UIntPtr value2
);
Parameters:

value1

A UIntPtr.

value2

A UIntPtr.

Return Value:
true if value1 equals value2; otherwise, false.

Return to top


Overloaded Method: op_Explicit System.UIntPtr(
   uint value
)
Summary
Converts the value of a 32-bit unsigned integer to an UIntPtr.
This class is not CLS Compliant

C# Syntax:
public static operator explicit UIntPtr(
   uint value
);
Parameters:

value

A 32-bit unsigned integer.

Return Value:
A new instance of UIntPtr initialized to value.
See also:
UIntPtr.#ctor

Return to top


Overloaded Method: op_Explicit System.UIntPtr(
   ulong value
)
Summary
Converts the value of a 64-bit unsigned integer to an UIntPtr.
This class is not CLS Compliant

C# Syntax:
public static operator explicit UIntPtr(
   ulong value
);
Parameters:

value

A 64-bit unsigned integer.

Return Value:
A new instance of UIntPtr initialized to value.
Exceptions
Exception Type Condition
OverflowException On a 32-bit platform, value is too large to represent as an UIntPtr.
See also:
UIntPtr.#ctor

Return to top


Overloaded Method: op_Explicit System.Void*(
   UIntPtr value
)
Summary
Converts the value of the specified UIntPtr to a pointer to an unspecified type.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public static operator explicit void*(
   UIntPtr value
);
Parameters:

value

A UIntPtr.

Return Value:
The contents of value.
See also:
UIntPtr.ToPointer

Return to top


Overloaded Method: op_Explicit System.UInt64(
   UIntPtr value
)
Summary
Converts the value of the specified UIntPtr to a 64-bit unsigned integer.
This class is not CLS Compliant

C# Syntax:
public static operator explicit ulong(
   UIntPtr value
);
Parameters:

value

A UIntPtr.

Return Value:
The contents of value.
See also:
UIntPtr.ToUInt64

Return to top


Overloaded Method: op_Explicit System.UInt32(
   UIntPtr value
)
Summary
Converts the value of the specified UIntPtr to a 32-bit unsigned integer.
This class is not CLS Compliant

C# Syntax:
public static operator explicit uint(
   UIntPtr value
);
Parameters:

value

A UIntPtr.

Return Value:
The contents of value.
Exceptions
Exception Type Condition
OverflowException On a 64-bit platform, the value of value is too large to represent as a 32-bit unsigned integer.
Remarks
An exception is only thrown if the value of value requires more bits than the current platform supports.
See also:
UIntPtr.ToUInt32

Return to top


Overloaded Method: op_Explicit System.UIntPtr(
   void* value
)
Summary
Converts the specified pointer to an unspecified type to a UIntPtr.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public static operator explicit UIntPtr(
   void* value
);
Parameters:

value

A pointer to an unspecified type.

Return Value:
A new instance of UIntPtr initialized to value.
See also:
UIntPtr.#ctor

Return to top


Method: op_Inequality(
   UIntPtr value1,
   UIntPtr value2
)
Summary
Determines whether two specified instances of UIntPtr are not equal.
This class is not CLS Compliant

C# Syntax:
public static bool operator !=(
   UIntPtr value1,
   UIntPtr value2
);
Parameters:

value1

A UIntPtr.

value2

A UIntPtr.

Return Value:
true if value1 does not equal value2; otherwise, false.

Return to top


Method: ToPointer()
Summary
Converts the value of this instance to a pointer to an unspecified type.
This class is not CLS Compliant

This member is not CLS Compliant

C# Syntax:
[CLSCompliant(false)]
unsafe public void* ToPointer();
Return Value:
A pointer to Void; that is, a pointer to memory containing data of an unspecified type.

Return to top


Overridden Method: ToString()
Summary
Converts the numeric value of this instance to its equivalent string representation.
This class is not CLS Compliant

C# Syntax:
public override string ToString();
Return Value:
The string representation of the value of this instance.
Remarks
If the value of the IntPtr.Size property for this instance is 4, then this method is equivalent to UInt32.ToString; otherwise, this method is equivalent to UInt64.ToString.

Return to top


Method: ToUInt32()
Summary
Converts the value of this instance to a 32-bit unsigned integer.
This class is not CLS Compliant

C# Syntax:
public uint ToUInt32();
Return Value:
A 32-bit unsigned integer equal to the value of this instance.
Exceptions
Exception Type Condition
OverflowException On a 64-bit platform, the value of this instance is too large to represent as a 32-bit unsigned integer.
Remarks
An exception is only thrown if the value of value requires more bits than the current platform supports.

Return to top


Method: ToUInt64()
Summary
Converts the value of this instance to a 64-bit unsigned integer.
This class is not CLS Compliant

C# Syntax:
public ulong ToUInt64();
Return Value:
A 64-bit unsigned integer equal to the value of this instance.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.