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.
foreach在 D 中使用时,循环索引的首选类型是什么int,uint或者通过省略类型来简单地自动执行?
foreach
int
uint
一般来说,索引应该是size_t. 与 相同length。如果您尝试使用int或uint. size_t是语言用于数组索引和length. uint它在 32 位机器和ulong64 位机器上具有别名。
size_t
length
ulong
所以,如果你要给索引一个类型,就给它size_t。但是,在迭代数组时会推断出类型size_t。foreach因此,在大多数情况下,没有理由列出类型。