Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我基本上是 c++ 人,现在正在学习 c#。虽然数组声明我发现 c# 需要类型后的方括号,这与 c、c++ 不同。c#语言规范是这样的有什么原因吗?
我能想到的唯一充分理由是明确指出此构造中 list1 和 list2 的类型:
在 C# 中:
int[] list1, list2;
list2 是一个整数数组。
在 C++ 中:
int list1[], list2;
list2 是一个整数。
可读性是这里的关键。
它也是为了一致性(这有助于提高可读性)。
在 C# 变量声明中,完整的类型说明始终位于变量名称的左侧。
在 C/C++ 中,有时类型规范的一部分位于变量名的右侧,这是不一致的。