UIntPtr 结构

定义

重要

此 API 不符合 CLS。

表示一个无符号整数,其中位宽度与指针相同。

public value class UIntPtr
public value class UIntPtr : IComparable, IComparable<UIntPtr>, IEquatable<UIntPtr>, IFormattable, System::Runtime::Serialization::ISerializable
public value class UIntPtr : IComparable, IComparable<UIntPtr>, IEquatable<UIntPtr>, ISpanFormattable, System::Runtime::Serialization::ISerializable
public value class UIntPtr : IComparable<UIntPtr>, IEquatable<UIntPtr>, IParsable<UIntPtr>, ISpanParsable<UIntPtr>, System::Numerics::IAdditionOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::IAdditiveIdentity<UIntPtr, UIntPtr>, System::Numerics::IBinaryInteger<UIntPtr>, System::Numerics::IBinaryNumber<UIntPtr>, System::Numerics::IBitwiseOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::IComparisonOperators<UIntPtr, UIntPtr>, System::Numerics::IDecrementOperators<UIntPtr>, System::Numerics::IDivisionOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::IEqualityOperators<UIntPtr, UIntPtr>, System::Numerics::IIncrementOperators<UIntPtr>, System::Numerics::IMinMaxValue<UIntPtr>, System::Numerics::IModulusOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::IMultiplicativeIdentity<UIntPtr, UIntPtr>, System::Numerics::IMultiplyOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::INumber<UIntPtr>, System::Numerics::INumberBase<UIntPtr>, System::Numerics::IShiftOperators<UIntPtr, UIntPtr>, System::Numerics::ISubtractionOperators<UIntPtr, UIntPtr, UIntPtr>, System::Numerics::IUnaryNegationOperators<UIntPtr, UIntPtr>, System::Numerics::IUnaryPlusOperators<UIntPtr, UIntPtr>, System::Numerics::IUnsignedNumber<UIntPtr>, System::Runtime::Serialization::ISerializable
public value class UIntPtr : IEquatable<UIntPtr>, System::Runtime::Serialization::ISerializable
public value class UIntPtr : System::Runtime::Serialization::ISerializable
[System.CLSCompliant(false)]
public struct UIntPtr
[System.CLSCompliant(false)]
public readonly struct UIntPtr : IComparable, IComparable<UIntPtr>, IEquatable<UIntPtr>, IFormattable, System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
public readonly struct UIntPtr : IComparable, IComparable<UIntPtr>, IEquatable<UIntPtr>, ISpanFormattable, System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
public readonly struct UIntPtr : IComparable<UIntPtr>, IEquatable<UIntPtr>, IParsable<UIntPtr>, ISpanParsable<UIntPtr>, System.Numerics.IAdditionOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.IAdditiveIdentity<UIntPtr,UIntPtr>, System.Numerics.IBinaryInteger<UIntPtr>, System.Numerics.IBinaryNumber<UIntPtr>, System.Numerics.IBitwiseOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.IComparisonOperators<UIntPtr,UIntPtr>, System.Numerics.IDecrementOperators<UIntPtr>, System.Numerics.IDivisionOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.IEqualityOperators<UIntPtr,UIntPtr>, System.Numerics.IIncrementOperators<UIntPtr>, System.Numerics.IMinMaxValue<UIntPtr>, System.Numerics.IModulusOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.IMultiplicativeIdentity<UIntPtr,UIntPtr>, System.Numerics.IMultiplyOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.INumber<UIntPtr>, System.Numerics.INumberBase<UIntPtr>, System.Numerics.IShiftOperators<UIntPtr,UIntPtr>, System.Numerics.ISubtractionOperators<UIntPtr,UIntPtr,UIntPtr>, System.Numerics.IUnaryNegationOperators<UIntPtr,UIntPtr>, System.Numerics.IUnaryPlusOperators<UIntPtr,UIntPtr>, System.Numerics.IUnsignedNumber<UIntPtr>, System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
public struct UIntPtr : IEquatable<UIntPtr>, System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
public readonly struct UIntPtr : IEquatable<UIntPtr>, System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
[System.Serializable]
public struct UIntPtr : System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct UIntPtr : System.Runtime.Serialization.ISerializable
[System.CLSCompliant(false)]
public struct UIntPtr : System.Runtime.Serialization.ISerializable
[<System.CLSCompliant(false)>]
type unativeint = struct
[<System.CLSCompliant(false)>]
type unativeint = struct
    interface IFormattable
    interface ISerializable
[<System.CLSCompliant(false)>]
type unativeint = struct
    interface ISpanFormattable
    interface IFormattable
    interface ISerializable
[<System.CLSCompliant(false)>]
type unativeint = struct
    interface IFormattable
    interface IParsable<unativeint>
    interface ISpanFormattable
    interface ISpanParsable<unativeint>
    interface IAdditionOperators<unativeint, unativeint, unativeint>
    interface IAdditiveIdentity<unativeint, unativeint>
    interface IBinaryInteger<unativeint>
    interface IBinaryNumber<unativeint>
    interface IBitwiseOperators<unativeint, unativeint, unativeint>
    interface IComparisonOperators<unativeint, unativeint>
    interface IEqualityOperators<unativeint, unativeint>
    interface IDecrementOperators<unativeint>
    interface IDivisionOperators<unativeint, unativeint, unativeint>
    interface IIncrementOperators<unativeint>
    interface IModulusOperators<unativeint, unativeint, unativeint>
    interface IMultiplicativeIdentity<unativeint, unativeint>
    interface IMultiplyOperators<unativeint, unativeint, unativeint>
    interface INumber<unativeint>
    interface INumberBase<unativeint>
    interface ISubtractionOperators<unativeint, unativeint, unativeint>
    interface IUnaryNegationOperators<unativeint, unativeint>
    interface IUnaryPlusOperators<unativeint, unativeint>
    interface IShiftOperators<unativeint, unativeint>
    interface IMinMaxValue<unativeint>
    interface IUnsignedNumber<unativeint>
    interface ISerializable
[<System.CLSCompliant(false)>]
type unativeint = struct
    interface ISerializable
[<System.CLSCompliant(false)>]
[<System.Serializable>]
type unativeint = struct
    interface ISerializable
[<System.CLSCompliant(false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type unativeint = struct
    interface ISerializable
Public Structure UIntPtr
Public Structure UIntPtr
Implements IComparable, IComparable(Of UIntPtr), IEquatable(Of UIntPtr), IFormattable, ISerializable
Public Structure UIntPtr
Implements IComparable, IComparable(Of UIntPtr), IEquatable(Of UIntPtr), ISerializable, ISpanFormattable
Public Structure UIntPtr
Implements IAdditionOperators(Of UIntPtr, UIntPtr, UIntPtr), IAdditiveIdentity(Of UIntPtr, UIntPtr), IBinaryInteger(Of UIntPtr), IBinaryNumber(Of UIntPtr), IBitwiseOperators(Of UIntPtr, UIntPtr, UIntPtr), IComparable(Of UIntPtr), IComparisonOperators(Of UIntPtr, UIntPtr), IDecrementOperators(Of UIntPtr), IDivisionOperators(Of UIntPtr, UIntPtr, UIntPtr), IEqualityOperators(Of UIntPtr, UIntPtr), IEquatable(Of UIntPtr), IIncrementOperators(Of UIntPtr), IMinMaxValue(Of UIntPtr), IModulusOperators(Of UIntPtr, UIntPtr, UIntPtr), IMultiplicativeIdentity(Of UIntPtr, UIntPtr), IMultiplyOperators(Of UIntPtr, UIntPtr, UIntPtr), INumber(Of UIntPtr), INumberBase(Of UIntPtr), IParsable(Of UIntPtr), ISerializable, IShiftOperators(Of UIntPtr, UIntPtr), ISpanParsable(Of UIntPtr), ISubtractionOperators(Of UIntPtr, UIntPtr, UIntPtr), IUnaryNegationOperators(Of UIntPtr, UIntPtr), IUnaryPlusOperators(Of UIntPtr, UIntPtr), IUnsignedNumber(Of UIntPtr)
Public Structure UIntPtr
Implements IEquatable(Of UIntPtr), ISerializable
Public Structure UIntPtr
Implements ISerializable
继承
UIntPtr
属性
实现
IComparable IComparable<UIntPtr> IEquatable<UIntPtr> IFormattable ISerializable ISpanFormattable IComparable<TOther> IComparable<TSelf> IEquatable<TOther> IEquatable<TSelf> IParsable<UIntPtr> IParsable<TSelf> ISpanParsable<UIntPtr> ISpanParsable<TSelf> IAdditionOperators<UIntPtr,UIntPtr,UIntPtr> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<UIntPtr,UIntPtr> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<UIntPtr> IBinaryNumber<UIntPtr> IBinaryNumber<TSelf> IBitwiseOperators<UIntPtr,UIntPtr,UIntPtr> IBitwiseOperators<TSelf,TSelf,TSelf> System.Numerics.IComparisonOperators<UIntPtr,UIntPtr> System.Numerics.IComparisonOperators<TSelf,TSelf> IDecrementOperators<UIntPtr> IDecrementOperators<TSelf> IDivisionOperators<UIntPtr,UIntPtr,UIntPtr> IDivisionOperators<TSelf,TSelf,TSelf> System.Numerics.IEqualityOperators<UIntPtr,UIntPtr> System.Numerics.IEqualityOperators<TSelf,TOther> System.Numerics.IEqualityOperators<TSelf,TSelf> IIncrementOperators<UIntPtr> IIncrementOperators<TSelf> IMinMaxValue<UIntPtr> IModulusOperators<UIntPtr,UIntPtr,UIntPtr> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<UIntPtr,UIntPtr> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<UIntPtr,UIntPtr,UIntPtr> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<UIntPtr> INumber<TSelf> INumberBase<UIntPtr> INumberBase<TSelf> System.Numerics.IShiftOperators<UIntPtr,UIntPtr> System.Numerics.IShiftOperators<TSelf,TSelf> ISubtractionOperators<UIntPtr,UIntPtr,UIntPtr> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<UIntPtr,UIntPtr> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<UIntPtr,UIntPtr> IUnaryPlusOperators<TSelf,TSelf> IUnsignedNumber<UIntPtr>

注解

UIntPtr 类型设计为一个整数,其大小与指针相同。 也就是说,此类型的实例应在 32 位进程中为 32 位,在 64 位进程中为 64 位。

UIntPtr 类型可由支持指针的语言使用,并且作为引用不同语言之间数据(不支持指针)的常见方法。 UIntPtr 对象还可用于保存句柄。

备注

用作 UIntPtr 指针或句柄容易出错且不安全。 它只是一种整数类型,由于大小相同,可用作指针和句柄的交换格式。 在特定的交换要求之外,例如将数据传递给不支持指针的语言,应使用正确类型的指针来表示指针, SafeHandle 并应用于表示句柄。

此类型实现 ISerializable. 在 .NET 5 及更高版本中,此类型还实现 IFormattable 接口。 在 .NET 7 及更高版本中,此类型还实现、IBinaryInteger<TSelf>IMinMaxValue<TSelf>接口和IUnsignedNumber<TSelf>接口。

从版本 9.0 开始的 C# 中,可以使用内置 nuint 类型来定义本机大小的整数。 此类型在内部由 UIntPtr 类型表示,并提供适用于整数类型的操作和转换。 有关详细信息,请参阅 nint 和 nuint 类型

在 C# 中,从版本 11 开始,面向 .NET 7 或更高版本运行时时,nuint是别名,采用与别名相同的方式UInt32uintUIntPtr

构造函数

UIntPtr(UInt32)

使用指定的 32 位无符号整数初始化结构的新实例 UIntPtr

UIntPtr(UInt64)

初始化使用指定的 64 位无符号整数的新实例 UIntPtr

UIntPtr(Void*)

使用指定的指向未指定类型的指针初始化 UIntPtr 的新实例。

字段

Zero

一个只读字段,表示已初始化为零的无符号整数。

属性

MaxValue

表示 UIntPtr 的最大可能值。

MinValue

表示 UIntPtr 的最小可能值。

Size

获取此实例的大小。

方法

Add(UIntPtr, Int32)

向无符号整数添加偏移量。

Clamp(UIntPtr, UIntPtr, UIntPtr)

将值固定到非独占最小值和最大值。

CompareTo(Object)

将当前实例与同一类型的另一个对象进行比较,并返回一个整数,该整数指示当前实例在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。

CompareTo(UIntPtr)

将当前实例与同一类型的另一个对象进行比较,并返回一个整数,该整数指示当前实例在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。

DivRem(UIntPtr, UIntPtr)

计算两个值的商和余数。

Equals(Object)

返回一个值,该值指示此实例是否等于指定的对象。

Equals(UIntPtr)

指示当前对象是否等于同一类型的另一个对象。

GetHashCode()

返回此实例的哈希代码。

IsEvenInteger(UIntPtr)

确定值是否表示偶数。

IsOddInteger(UIntPtr)

确定值是否表示奇数整数。

IsPow2(UIntPtr)

确定值是否为 2 的幂。

LeadingZeroCount(UIntPtr)

计算值中的前导零数。

Log2(UIntPtr)

计算值的 log2。

Max(UIntPtr, UIntPtr)

将两个值与计算进行比较,该值更大。

Min(UIntPtr, UIntPtr)

比较两个值,计算值越少。

Parse(ReadOnlySpan<Char>, IFormatProvider)
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

将具有可选指定样式的数字的字符表示形式的只读范围和指定区域性特定的格式转换为其等效的无符号本机整数。

Parse(String)

将数字的字符串表示形式转换为它的等效无符号本机整数。

Parse(String, IFormatProvider)

将指定区域性特定格式的数字的字符串表示形式转换为它的等效无符号本机整数。

Parse(String, NumberStyles)

将指定样式的数字的字符串表示形式转换为它的等效无符号本机整数。

Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效无符号本机整数。

PopCount(UIntPtr)

计算值中设置的位数。

RotateLeft(UIntPtr, Int32)

按给定量旋转值。

RotateRight(UIntPtr, Int32)

按给定量向右旋转值。

Sign(UIntPtr)

计算值的符号。

Subtract(UIntPtr, Int32)

从无符号整数中减去偏移量。

ToPointer()

将此实例的值转换为指向未指定类型的指针。

ToString()

将此实例的数值转换为其等效的字符串表示形式。

ToString(IFormatProvider)

使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。

ToString(String)

使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。

ToString(String, IFormatProvider)

使用指定格式对当前实例的值设置格式。

ToUInt32()

将此实例的值转换成 32 位无符号整数。

ToUInt64()

将此实例的值转换成 64 位无符号整数。

TrailingZeroCount(UIntPtr)

计算值中的尾随零数。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前实例的值格式化为提供的字符范围。

TryParse(ReadOnlySpan<Char>, IFormatProvider, UIntPtr)
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, UIntPtr)

将指定样式和区域性特定格式的数字的字符表示形式的只读范围转换为其等效的无符号本机整数。 一个指示转换是否成功的返回值。

TryParse(ReadOnlySpan<Char>, UIntPtr)

将数字的字符表示形式的只读范围转换为其等效的无符号本机整数。 一个指示转换是否成功的返回值。

TryParse(String, IFormatProvider, UIntPtr)
TryParse(String, NumberStyles, IFormatProvider, UIntPtr)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效无符号本机整数。 一个指示转换是否成功的返回值。

TryParse(String, UIntPtr)

将数字的字符串表示形式转换为它的等效无符号本机整数。 一个指示转换是否成功的返回值。

运算符

Addition(UIntPtr, Int32)

向无符号整数添加偏移量。

Equality(UIntPtr, UIntPtr)

确定 UIntPtr 的两个指定的实例是否相等。

Explicit(UInt32 to UIntPtr)

将 32 位无符号整数的值转换成 UIntPtr

Explicit(UInt64 to UIntPtr)

将 64 位无符号整数的值转换成 UIntPtr

Explicit(UIntPtr to UInt32)

将指定的 UIntPtr 的值转换为 32 位无符号整数。

Explicit(UIntPtr to UInt64)

将指定的 UIntPtr 的值转换为 64 位无符号整数。

Explicit(UIntPtr to Void*)

将指定的 UIntPtr 的值转换为指向未指定类型的指针。

此 API 不兼容 CLS。

Explicit(Void* to UIntPtr)

将指向未指定类型的指定指针转换为 UIntPtr

此 API 不兼容 CLS。

Inequality(UIntPtr, UIntPtr)

确定 UIntPtr 的两个指定的实例是否不等。

Subtraction(UIntPtr, Int32)

从无符号整数中减去偏移量。

显式接口实现

IBinaryInteger<UIntPtr>.GetByteCount()

获取将作为其一部分 TryWriteLittleEndian(Span<Byte>, Int32)写入的字节数。

IBinaryInteger<UIntPtr>.GetShortestBitLength()

获取最短两个当前值的补充表示形式的长度(以位为单位)。

IBinaryInteger<UIntPtr>.TryWriteBigEndian(Span<Byte>, Int32)

尝试将当前值(采用大端格式)写入给定范围。

IBinaryInteger<UIntPtr>.TryWriteLittleEndian(Span<Byte>, Int32)

尝试将当前值(以小端格式)写入给定范围。

IEquatable<UIntPtr>.Equals(UIntPtr)

返回一个值,该值指示此实例是否等于另一个无符号整数。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化当前的 SerializationInfo 对象所需的所有数据填充 UIntPtr 对象。

适用于

线程安全性

此类型是线程安全的。

另请参阅