java - Go、Java 和 C# 中数组的最大长度是多少?

标签 java c# go

<分区>

我可以在 Go、Java 和 C# 中声明的数组的最大长度是多少?它与运行时的最大内存有关吗?或者他们有标准吗?

最佳答案

The Go Programming Language Specification

Array types

An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length and is never negative.

The length is part of the array's type; it must evaluate to a non-negative constant representable by a value of type int.

Numeric types

A numeric type represents sets of integer or floating-point values.

There is a set of predeclared numeric types with implementation-specific sizes:

uint     the set of all unsigned integers, either 32 or 64 bits
int      the set of all signed integers, same size as uint

Go数组长度是int类型的值,是32位或64位有符号整数,取决于编译架构(GOARCH),例如386或amd64。它还受任何硬件或操作系统内存大小限制。

package main

import (
    "fmt"
    "runtime"
    "strconv"
)

func main() {
    fmt.Println("int is", strconv.IntSize, "bits on", runtime.GOARCH)
}

输出:

int is 64 bits on amd64

关于java - Go、Java 和 C# 中数组的最大长度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622422/

相关文章:

java - 使用java firebase的android studio中的IF语句计数++

c# - 无法向 Google 电子表格添加行

c# - 使用 AutoMapper 从接口(interface)推断目标类型

java - 在 Quartz-Scheduler 中创建 bean 时出错

java - 如何根据对象属性知道 map 是否包含该对象

c# - 从字符串中删除单个字符?

go - 比赛模拟 fatal error : all goroutines are asleep - deadlock

database - 如何使用没有循环指针的反射在 Golang 中调用 Scan variadic 函数?

arrays - 在 Golang 中替换数组结构中的数据

java - 使用 Excel 报告中的 DynamicJasper 在列页脚中添加自定义计算