Sử dụng BigInteger để xử lý số lớn trong C#. Assembly cần thêm cho BigInteger là System.Numerics.
Trong C#, BigInteger nằm trong System.Numerics.BigInteger.
Cú pháp
Cú pháp của BigInteger:
[SerializableAttribute] public struct BigInteger : IFormattable, IComparable, IComparable<BigInteger>, IEquatable<BigInteger>
Hãy xem đoạn mã ví dụ:
BigInteger num = BigInteger.Multiply(Int64.MaxValue, Int64.MaxValue);
Bạn có thể tạo BigInteger như sau:
BigInteger num = new BigInteger(double.MaxValue);
Dưới đây là một số constructor của nó:
| Số thứ tự | Constructor & Mô tả |
|---|---|
| 1 | BigInteger(Byte[]) Thể hiện mới của cấu trúc BigInteger sử dụng giá trị trong mảng byte. |
| 2 | BigInteger(Decimal) Thể hiện mới sử dụng giá trị Decimal. |
| 3 | BigInteger(Double) Thể hiện mới sử dụng giá trị double-precision floating-point. |
| 4 | BigInteger(Int32) Thể hiện mới sử dụng giá trị signed 32-bit integer. |