本文介绍了int i vs int index等。哪一个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直使用 int i 用于通用循环变量。当然,在大的嵌套循环或其他复杂的东西,我可以使用一个描述性的名字,但你最喜欢看哪一个。

Coming from a C background I've always used int i for generic loop variables. Of course in big nested loops or other complex things I may use a descriptive name but which one had you rather see?

int i;
for(i=0;i<Controls.Count;i++){
  DoStuff(Controls[i]);
}

int index;
for(index=0;index<Controls.Count;index++){
  DoStuff(Controls[index]);
}

在当前项目中,我正在处理这两种样式和索引由 ndx 替换。

In the current project I am working on there are both of these styles and index being replaced by ndx.

哪一个更好? i 变量太泛吗?还有其他C风格名称? i,j,k 是否所有这些都被实际的描述性变量取代?

Which one is better? Is the i variable too generic? Also what about the other C style names? i, j, k Should all of these be replaced by actual descriptive variables?

推荐答案

i 在第一个循环中是非常标准的,其次是 j

i, however, is pretty standard in terms of the first loop, followed by j for an inner loop and k for an inner-inner loop, and so on.

与几乎所有的命名规则一样,对于内部循环, k 只要它是一个项目的标准,并为所有成员工作良好,那么很好。

As with almost all naming rules, as long as it is standard within a project, and works well for all members thereof, then it's fine.

这篇关于int i vs int index等。哪一个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:25