<分区>
我刚刚开始学习golang
的一些基础知识,在查看数组定义语法时对我来说有点奇怪。
C++/C#/Java 都定义了多维数组,如:
int arr[X][Y][Z]; // C/C++
int[,,] arr = new int[X, Y, Z]; // C#
int[][][] multi = new int[X][Y][Z]; // Java
继续:
var arr [Z][Y][X]int32 // go
语法的优点是什么?
<分区>
我刚刚开始学习golang
的一些基础知识,在查看数组定义语法时对我来说有点奇怪。
C++/C#/Java 都定义了多维数组,如:
int arr[X][Y][Z]; // C/C++
int[,,] arr = new int[X, Y, Z]; // C#
int[][][] multi = new int[X][Y][Z]; // Java
继续:
var arr [Z][Y][X]int32 // go
语法的优点是什么?
最佳答案
C# 和 Java 的语法都受到 C 的启发,并继承了 C 语法的所有怪癖。关于为什么 Go has a different syntax 有一篇很好的文章:
Go syntax
Languages outside the C family usually use a distinct type syntax in declarations. Although it's a separate point, the name usually comes first, often followed by a colon. Thus our examples above become something like (in a fictional but illustrative language)
x: int p: pointer to int a: array[3] of int
These declarations are clear, if verbose - you just read them left to right. Go takes its cue from here, but in the interests of brevity it drops the colon and removes some of the keywords:
x int p *int a [3]int
There is no direct correspondence between the look of
[3]int
and how to use a in an expression. (We'll come back to pointers in the next section.) You gain clarity at the cost of a separate syntax.
关于java - golang为[z][y][x]int定义数组int[x][y][z]有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610154/
相关文章:
java - 如何将 IObservableSet 绑定(bind)到 IObservableList?
c# - 如何编写正则表达式以将 HEX 值与变量声明相匹配?
c++ - 在 C++ 中将 AES 加密字符串转换为十六进制
c# - Unidata UniObjects for .NET - 将修改内容从修改后的表写回到 unidata
c++ - 在 std::deque 中移动元素的有效方法?
java - Oracle 的 jvm 中的 notify() 实现
java - Eclipse不可逆Dynamic Web Module 4.0选择; Tomcat 9 不支持