C# 中 SQL Bigint 的等價物
SQL 中的 bigint 資料型別是整數的 64 位表示。它佔用 8 個位元組的儲存空間,範圍從 -2^63 (-9,223,372,036,854,775,808) 到 2^63 (9,223,372,036,854,775,807)。
它代表一個非常大的數字,儲存這些型別的數字需要在 C# 中類似的東西。在本教程中,你將瞭解在 C# 中使用什麼資料型別來等效於 bigint。
在 C# 中,所有數值資料型別都儲存有限範圍的值。此外,為了消除最大和最小數量限制,C# 包含 BigInteger 資料型別,表示一個任意大的有符號整數,沒有上限或下限。
使用 C# 中的 BigInteger 結構作為 SQL bigint 的等價物
BigInteger 是不可變的結構型別,沒有最大值或最小值限制。它是 System.Numerics 名稱空間的一部分,理論上沒有上限或下限。
它的成員或資料與 C# 中的其他整數型別非常相似。
它與 .NET 框架中的其他整數型別不同,因為它沒有 MinValue 和 MaxValue 屬性。它使你能夠通過過載標準數字運算子來執行主要的數學運算。
using System;
using System.Numerics;
public class HelloWorld {
public static void Main(string[] args) {
// declaring a BigInteger
// Use new keyword to instantiate BigInteger values
// it can store a value from a double type
BigInteger number1 = new BigInteger(209857.1946);
Console.WriteLine(number1 + "");
// it can store a value from an Int64 type
BigInteger number2 = new BigInteger(947685917234);
Console.WriteLine(number2);
}
}
輸出:
209857
947685917234
在 C# 中使用 long 或 int64 作為 SQL bigint 的等價物
C# 中的 long 資料型別表示 64 位或 8 位元組整數,類似於 bigint。它可以表示極大的正整數和負整數。
它是一種不可變值型別,表示有符號整數,其值的範圍從負 9,223,372,036,854,775,808(由 Int64.MinValue 常量表示)到正 9,223,372,036,854,775,807(由 Int64.MaxValue 常量表示)。
using System;
public class dataTypeforBI {
public static void Main(string[] args) {
long number1 = -64301728;
Console.WriteLine(number1 + "");
long number2 = 255486129307;
Console.WriteLine(number2);
}
}
輸出:
-64301728
255486129307
Hassan is a Software Engineer with a well-developed set of programming skills. He uses his knowledge and writing capabilities to produce interesting-to-read technical articles.
GitHub