for (int i = 0; i < 90; i++)
{
comboBox1.Items.Add("Reduced by: " + i.ToString());
}
这将向comboBox1添加90个项目。 我想添加9项10,20,30,40,50,60,70,80,90
如何在跳跃10中添加它?
答案 0 :(得分:3)
for (int i = 10; i <= 90; i+=10)
{
comboBox1.Items.Add("Reduced by: " + i.ToString());
}
答案 1 :(得分:2)
试试这样:
for (int i = 10; i <= 90; i=i+10)
{
comboBox1.Items.Add("Reduced by: " + i.ToString());
}
或:
for (int i = 10; i < 100; i=i+10)
{
comboBox1.Items.Add("Reduced by: " + i.ToString());
}
答案 2 :(得分:0)
这是一个清晰但很长的版本。请注意,这使用了一个额外的辅助变量,并且循环次数是原始方法的90倍,这不如mr100的答案效率高:
int cnt = 0;
for (int i = 1; i <= 90; i++)
{
cnt++;
if (cnt == 10)
{
comboBox1.Items.Add("Reduced by: " + i.ToString());
cnt = 0; //Reset
}
}