BigInteger ใช้จัดการเลขจำนวนเต็มขนาดใหญ่ไม่จำกัดขนาด (Limited by memory only)
Namespace: System.Numerics (ต้อง Add Reference: System.Numerics.dll)
Syntax
[Serializable] public struct BigInteger : IFormattable, IComparable, IComparable, IEquatable
Constructors หลัก
| Constructor | คำอธิบาย |
|---|---|
| BigInteger(Byte[]) | สร้างจาก Byte array (Little-endian) |
| BigInteger(Decimal) | สร้างจาก Decimal |
| BigInteger(Double) | สร้างจาก Double |
| BigInteger(Int32) | สร้างจาก 32-bit signed integer |
| BigInteger(Int64) | สร้างจาก 64-bit signed integer |
| BigInteger(UInt32) | สร้างจาก 32-bit unsigned integer |
| BigInteger(UInt64) | สร้างจาก 64-bit unsigned integer |
ตัวอย่างการใช้งาน
using System; using System.Numerics; BigInteger big = BigInteger.Multiply(Int64.MaxValue, Int64.MaxValue); // หรือ BigInteger big2 = new BigInteger(123456789012345678901234567890); // รองรับ operators ทั่วไป BigInteger a = 1000000; BigInteger b = 2000000; BigInteger sum = a + b; BigInteger product = a * b; BigInteger pow = BigInteger.Pow(2, 1000); // 2^1000
เมธอดสำคัญ
Parse(string)/TryParse- แปลงจาก StringToString()- แปลงเป็น StringGreatestCommonDivisor(a, b)- หาตัวหารร่วมมากModPow(value, exponent, modulus)- Modular exponentiation (สำคัญสำหรับ Cryptography)