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
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。