Bilangan bulat asli nint
dan nuint
yang sederhana, ditulis dalam IL, mungkin yang terbaik kedua setelah dukungan kompiler yang tepat. Berfungsi penuh.
DotNetCross.NativeInts
https://www.nuget.org/packages/DotNetCross.NativeInts
nint
API public struct nint : IEquatable < nint > , IComparable < nint >
{
public static readonly nint Zero ;
public IntPtr Value ;
public nint ( IntPtr value ) ;
public nint ( int value ) ;
public nint ( long value ) ;
public int CompareTo ( nint other ) ;
public override bool Equals ( object obj ) ;
public bool Equals ( nint other ) ;
public override int GetHashCode ( ) ;
public override string ToString ( ) ;
public static nint operator + ( nint value ) ;
public static nint operator + ( nint l , nint r ) ;
public static nint operator + ( nint l , int r ) ;
public static nint operator + ( int l , nint r ) ;
public static nint operator - ( nint value ) ;
public static nint operator - ( nint l , int r ) ;
public static nint operator - ( nint l , nint r ) ;
public static nint operator - ( int l , nint r ) ;
public static nint operator ~ ( nint value ) ;
public static nint operator ++ ( nint value ) ;
public static nint operator -- ( nint value ) ;
public static nint operator * ( nint l , nint r ) ;
public static nint operator * ( nint l , int r ) ;
public static nint operator / ( nint l , int r ) ;
public static nint operator / ( nint l , nint r ) ;
public static nint operator % ( nint l , nint r ) ;
public static nint operator % ( nint l , int r ) ;
public static nint operator & ( nint l , int r ) ;
public static nint operator & ( nint l , nint r ) ;
public static nint operator | ( nint l , nint r ) ;
public static nint operator | ( nint l , int r ) ;
public static nint operator ^ ( nint l , nint r ) ;
public static nint operator ^ ( nint l , int r ) ;
public static nint operator << ( nint l , nint r ) ;
public static nint operator << ( nint l , int r ) ;
public static nint operator >> ( nint l , nint r ) ;
public static nint operator >> ( nint l , int r ) ;
public static bool operator == ( IntPtr l , nint r ) ;
public static bool operator == ( nint l , IntPtr r ) ;
public static bool operator == ( nint l , long r ) ;
public static bool operator == ( long l , nint r ) ;
public static bool operator == ( nint l , int r ) ;
public static bool operator == ( nint l , nint r ) ;
public static bool operator == ( int l , nint r ) ;
public static bool operator != ( IntPtr l , nint r ) ;
public static bool operator != ( long l , nint r ) ;
public static bool operator != ( nint l , IntPtr r ) ;
public static bool operator != ( nint l , long r ) ;
public static bool operator != ( int l , nint r ) ;
public static bool operator != ( nint l , int r ) ;
public static bool operator != ( nint l , nint r ) ;
public static bool operator < ( IntPtr l , nint r ) ;
public static bool operator < ( nint l , IntPtr r ) ;
public static bool operator < ( long l , nint r ) ;
public static bool operator < ( nint l , long r ) ;
public static bool operator < ( int l , nint r ) ;
public static bool operator < ( nint l , nint r ) ;
public static bool operator < ( nint l , int r ) ;
public static bool operator > ( IntPtr l , nint r ) ;
public static bool operator > ( long l , nint r ) ;
public static bool operator > ( nint l , long r ) ;
public static bool operator > ( int l , nint r ) ;
public static bool operator > ( nint l , int r ) ;
public static bool operator > ( nint l , nint r ) ;
public static bool operator > ( nint l , IntPtr r ) ;
public static bool operator <= ( nint l , int r ) ;
public static bool operator <= ( IntPtr l , nint r ) ;
public static bool operator <= ( nint l , IntPtr r ) ;
public static bool operator <= ( long l , nint r ) ;
public static bool operator <= ( nint l , long r ) ;
public static bool operator <= ( int l , nint r ) ;
public static bool operator <= ( nint l , nint r ) ;
public static bool operator >= ( nint l , nint r ) ;
public static bool operator >= ( nint l , IntPtr r ) ;
public static bool operator >= ( long l , nint r ) ;
public static bool operator >= ( nint l , long r ) ;
public static bool operator >= ( int l , nint r ) ;
public static bool operator >= ( nint l , int r ) ;
public static bool operator >= ( IntPtr l , nint r ) ;
public static implicit operator long ( nint value ) ;
public static implicit operator IntPtr ( nint value ) ;
public static implicit operator nint ( int value ) ;
public static implicit operator nint ( IntPtr value ) ;
public static explicit operator nint ( long value ) ;
public static explicit operator int ( nint value ) ;
}
nuint
API public struct nuint : IEquatable < nuint > , IComparable < nuint >
{
public static readonly nuint Zero ;
public UIntPtr Value ;
public nuint ( UIntPtr value ) ;
public nuint ( uint value ) ;
public nuint ( ulong value ) ;
public int CompareTo ( nuint other ) ;
public override bool Equals ( object obj ) ;
public bool Equals ( nuint other ) ;
public override int GetHashCode ( ) ;
public override string ToString ( ) ;
public static nuint operator + ( nuint value ) ;
public static nuint operator + ( nuint l , nuint r ) ;
public static nuint operator + ( nuint l , uint r ) ;
public static nuint operator + ( uint l , nuint r ) ;
public static nuint operator - ( nuint l , uint r ) ;
public static nuint operator - ( nuint l , nuint r ) ;
public static nuint operator - ( uint l , nuint r ) ;
public static nuint operator ~ ( nuint value ) ;
public static nuint operator ++ ( nuint value ) ;
public static nuint operator -- ( nuint value ) ;
public static nuint operator * ( nuint l , nuint r ) ;
public static nuint operator * ( nuint l , uint r ) ;
public static nuint operator / ( nuint l , nuint r ) ;
public static nuint operator / ( nuint l , uint r ) ;
public static nuint operator % ( nuint l , nuint r ) ;
public static nuint operator % ( nuint l , uint r ) ;
public static nuint operator & ( nuint l , uint r ) ;
public static nuint operator & ( nuint l , nuint r ) ;
public static nuint operator | ( nuint l , uint r ) ;
public static nuint operator | ( nuint l , nuint r ) ;
public static nuint operator ^ ( nuint l , uint r ) ;
public static nuint operator ^ ( nuint l , nuint r ) ;
public static nuint operator << ( nuint l , nuint r ) ;
public static nuint operator << ( nuint l , uint r ) ;
public static nuint operator >> ( nuint l , nuint r ) ;
public static nuint operator >> ( nuint l , uint r ) ;
public static bool operator == ( nuint l , UIntPtr r ) ;
public static bool operator == ( UIntPtr l , nuint r ) ;
public static bool operator == ( nuint l , ulong r ) ;
public static bool operator == ( ulong l , nuint r ) ;
public static bool operator == ( nuint l , uint r ) ;
public static bool operator == ( nuint l , nuint r ) ;
public static bool operator == ( uint l , nuint r ) ;
public static bool operator != ( UIntPtr l , nuint r ) ;
public static bool operator != ( ulong l , nuint r ) ;
public static bool operator != ( nuint l , UIntPtr r ) ;
public static bool operator != ( nuint l , ulong r ) ;
public static bool operator != ( uint l , nuint r ) ;
public static bool operator != ( nuint l , uint r ) ;
public static bool operator != ( nuint l , nuint r ) ;
public static bool operator < ( UIntPtr l , nuint r ) ;
public static bool operator < ( nuint l , UIntPtr r ) ;
public static bool operator < ( ulong l , nuint r ) ;
public static bool operator < ( nuint l , ulong r ) ;
public static bool operator < ( uint l , nuint r ) ;
public static bool operator < ( nuint l , nuint r ) ;
public static bool operator < ( nuint l , uint r ) ;
public static bool operator > ( UIntPtr l , nuint r ) ;
public static bool operator > ( ulong l , nuint r ) ;
public static bool operator > ( nuint l , ulong r ) ;
public static bool operator > ( uint l , nuint r ) ;
public static bool operator > ( nuint l , uint r ) ;
public static bool operator > ( nuint l , nuint r ) ;
public static bool operator > ( nuint l , UIntPtr r ) ;
public static bool operator <= ( nuint l , uint r ) ;
public static bool operator <= ( UIntPtr l , nuint r ) ;
public static bool operator <= ( nuint l , UIntPtr r ) ;
public static bool operator <= ( ulong l , nuint r ) ;
public static bool operator <= ( nuint l , ulong r ) ;
public static bool operator <= ( uint l , nuint r ) ;
public static bool operator <= ( nuint l , nuint r ) ;
public static bool operator >= ( nuint l , nuint r ) ;
public static bool operator >= ( nuint l , UIntPtr r ) ;
public static bool operator >= ( ulong l , nuint r ) ;
public static bool operator >= ( nuint l , ulong r ) ;
public static bool operator >= ( uint l , nuint r ) ;
public static bool operator >= ( nuint l , uint r ) ;
public static bool operator >= ( UIntPtr l , nuint r ) ;
public static implicit operator ulong ( nuint value ) ;
public static implicit operator UIntPtr ( nuint value ) ;
public static implicit operator nuint ( uint value ) ;
public static implicit operator nuint ( UIntPtr value ) ;
public static explicit operator nuint ( ulong value ) ;
public static explicit operator uint ( nuint value ) ;
}
IntPtr
/ UIntPtr
vs nint
/ nuint
Berdasarkan:
Selain mendukung konversi implisit untuk:
IntPtr
ke/dari nint
UIntPtr
ke/dari nuint
Konversi berikut didukung dibandingkan dengan konversi yang tersedia untuk IntPtr
/ UIntPtr
.
Nama | Dari | IntPtr C# | UIntPtr C# | nint C# | nuint C# |
---|---|---|---|---|---|
op_Implisit | int | T/A | T/A | Ya | T/A |
op_Implisit | uint | T/A | T/A | T/A | Ya |
op_Eksplisit | long | T/A | T/A | Ya | T/A |
op_Eksplisit | ulong | T/A | T/A | T/A | Ya |
Nama | Ke | IntPtr C# | UIntPtr C# | nint C# | nuint C# |
---|---|---|---|---|---|
op_Implisit | long | T/A | T/A | Ya | T/A |
op_Implisit | ulong | T/A | T/A | T/A | Ya |
op_Eksplisit | int | T/A | T/A | Ya | T/A |
op_Eksplisit | uint | T/A | T/A | T/A | Ya |
Nama | Simbol Operator C++ | IntPtr C# | UIntPtr C# | nint C# | nuint C# |
---|---|---|---|---|---|
op_Penurunan | -- 1 | T/A | T/A | Ya | Ya |
op_Peningkatan | ++ 1 | T/A | T/A | Ya | Ya |
op_UnaryNegation | - (unary) | T/A | T/A | Ya | Ya |
op_UnaryPlus | + (unary) | T/A | T/A | Ya | Ya |
op_LogicalNot | ! | T/A | T/A | T/A | T/A |
op_Benar | dan 2 | T/A | T/A | T/A | T/A |
op_False | dan 2 | T/A | T/A | T/A | T/A |
op_AddressOf | & (unary) | T/A | T/A | T/A | T/A |
op_OnesComplement | ~ | T/A | T/A | Ya | Ya |
op_PointerDereference | * (unary) | T/A | T/A | T/A | T/A |
1 Dari sudut pandang C++ murni, cara seseorang menulis fungsi-fungsi ini untuk CLI berbeda dalam satu aspek yang sangat penting. Di C++, metode ini harus menambah atau mengurangi operannya secara langsung, sedangkan di CLI, metode ini tidak boleh; sebaliknya, mereka hanya mengembalikan nilai operannya +/- 1, sebagaimana mestinya, tanpa mengubah operannya. Operan harus ditambah atau dikurangi oleh kompiler yang menghasilkan kode untuk operator ++/--, terpisah dari panggilan ke metode ini.
2 Operator op_True dan op_False tidak ada di C++. Mereka disediakan untuk mendukung tipe Boolean tristate, seperti yang digunakan dalam bahasa database.
Tabel di bawah menunjukkan tipe yang dapat digunakan bersama dengan tipe di header untuk operator biner tertentu. Secara default, ini untuk tipe ekspresi di sisi kiri atau kanan (operator biner). Namun, untuk beberapa kasus, operator mungkin hanya tersedia untuk tipe pada sisi ekspresi tertentu, dengan (R)
berarti "hanya yang benar".
Nama | Simbol Operator C++ | IntPtr C# | UIntPtr C# | nint C# | nuint C# |
---|---|---|---|---|---|
op_Penambahan | + | int (R) | int (R) | nint , IntPtr , int | nuint , UIntPtr , uint |
op_Pengurangan | - | int (R) | int (R) | nint , IntPtr , int | nuint , UIntPtr , uint |
op_Kalikan | * | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_Divisi | / | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_Modulus | % | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_ExclusiveOr | ^ | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_BitwiseAnd | & | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_BitwiseOr | | | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_LogicalAnd | && | T/A | T/A | T/A | T/A |
op_LogicalOr | || | T/A | T/A | T/A | T/A |
op_Assign | T/D (= tidak sama) | T/A | T/A | T/A | T/A |
op_LeftShift | << | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_Pergeseran Kanan | >> | T/A | T/A | nint , IntPtr , int (R) | nuint , UIntPtr , uint (R) |
op_SignedRightShift | T/D | T/A | T/A | T/A | T/A |
op_UnsignedRightShift | T/D | T/A | T/A | T/A | T/A |
op_Kesetaraan | == | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_Lebih BesarDari | > | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_LessThan | < | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_Ketimpangan | != | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_GreaterThanOrEqual | >= | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_LessThanOrEqual | <= | IntPtr | UIntPtr | nint , IntPtr , int , long | nuint , UIntPtr , uint , ulong |
op_UnsignedRightShiftAssignment | Tidak ditentukan | T/A | T/A | T/A | T/A |
op_MemberSeleksi | -> | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) |
op_Penugasan Shift Kanan | >>= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_Penugasan Multiplikasi | *= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_PointerToMemberSelection | ->* | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) |
op_Penugasan Pengurangan | -= | int | int | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_ExclusiveOrAssignment | ^= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_LeftShiftAssignment | <<= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_ModulusAssignment | %= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_PenambahanPenugasan | += | int | int | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_BitwiseAndAssignment | &= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_BitwiseOrAssignment | |= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
op_Comma | , | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) | T/A (T/OC#) |
op_DivisionAssignment | /= | T/A (T/OC#) | T/A (T/OC#) | nint , IntPtr , int | nuint , UIntPtr , uint TODO |
N/A
= Tidak TersediaN/O
= Tidak Dapat Berlebihan, tetapi untuk operator penugasan dapat digunakan melalui operator statis biner misalnya +=
tersedia melalui +
. Metode berikut memiliki implementasi IntPtr
/ UIntPtr
yang sama atau meneruskannya.
public override bool Equals ( object obj )
public override int GetHashCode ( )
public override string ToString ( )
Antarmuka berikut telah diimplementasikan untuk tipe tertentu nint
atau nuint
:
IEquatable < T >
IComparable < T >