C# 中 Int64 与 UInt64 的区别

在我们深入探讨 C# 的数据类型时,了解不同数值类型的特性对于编写健壮的代码至关重要。今天,让我们来详细对比一下 INLINECODEaa517b4a 和 INLINECODE3c90124c 这两种结构体,看看它们在存储范围和使用场景上有何不同。

INLINECODEea9961d4 结构体用于表示 64位有符号整数。这意味着 INLINECODEc9511de8 可以存储包括负数和正数在内的两种类型的值,其范围从 -9,223,372,036,854,775,808 到 +9,223,372,036,854,775,807

示例:

// C# 程序演示 Int64 和 UInt64 的区别

using System;
using System.Text;

public class GFG {

    // Main 方法
    static void Main(string[] args) {

        // 打印最小值和最大值
        Console.WriteLine("Minimum value of Int64: " 
                          + Int64.MinValue);
        Console.WriteLine("Maximum value of Int64: " 
                          + Int64.MaxValue);
        Console.WriteLine();

        // Int64 数组
        Int64[] arr1 = {-3, 0, 1, 3, 7};

        foreach (Int64 i in arr1)
        { 
            Console.WriteLine(i);
        }
    }
}

输出:

Minimum value of Int64: -9223372036854775808
Maximum value of Int64: 9223372036854775807

-3
0
1
3
7

INLINECODEbecda5d6 结构体用于表示 64位无符号整数。这意味着 INLINECODEc25ff187 仅能存储正值,其范围为 0 到 18,446,744,073,709,551,615

示例:

// C# 程序演示 Int64 和 UInt64 的区别

using System;
using System.Text;

public class GFG{
    
    // Main 方法
    static void Main(string[] args)
    {

        // 打印最小值和最大值
        Console.WriteLine("Minimum value of UInt64: "
                          + UInt64.MinValue);
        Console.WriteLine("Maximum value of UInt64: "
                          + UInt64.MaxValue);
        Console.WriteLine();
        
        // UInt64 数组
        UInt64[] arr1 = { 13, 0, 1, 3, 7};
        
        foreach (UInt64 i in arr1)
        {
            Console.WriteLine(i);
        }
    }
}

输出:

Minimum value of UInt64: 0
Maximum value of UInt64: 18446744073709551615

13
0
1
3
7
序号

INT64

UINT64 —

— 1.

Int64 用于表示 64位有符号整数

UInt64 用于表示 64位无符号整数。 2.

Int64 代表有符号整数。

UInt64 代表无符号整数。 3.

它可以存储负数和正数。

它仅能存储正数。 4.

它在内存中占用 8字节 空间。

它在内存中也占用 8字节 空间。 5.

Int64 的范围是从 -9223372036854775808 到 +9223372036854775807。

UInt64 的范围是从 0 到 18446744073709551615。 6.

声明 Int64 的语法:
INLINECODE8a548094

声明 UInt64 的语法:
INLINECODE
82becb97
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。如需转载,请注明文章出处豆丁博客和来源网址。https://shluqu.cn/28093.html
点赞
0.00 平均评分 (0% 分数) - 0