C Sharp for循环问题 [英] C Sharp for loop problem

查看:190
本文介绍了C Sharp for循环问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如果我们想在for循环中每次将索引i增加到1,我们写i ++

但是我想每次将i增加到7。我已经给了我的代码。请有人帮帮我!!!



  if (ddlMaintenPlan .SelectedItem.Text ==  每周
{

DateTime dtLastday = Convert.ToDateTime(dtpMaintenceEnd.Text.Trim());
while (dsStartDate < = dtLastday)
{

for int i = Convert.ToInt32(dsStartDate); i < Convert.ToInt32(dtLastday); i ++)
{
dsStartDate = Convert.ToDateTime(Convert.ToInt32(dsStartDate)+ Convert.ToInt32(i.ToString() ));
DRLocal = DTLocal.NewRow();
DTLocal.Rows.Add(dsStartDate);
}
}



}

解决方案

  for  int  i = Convert.ToInt32(dsStartDate); i <  Convert.ToInt32(dtLastday); i + =  7 


I know that if we want to increase the index i into 1 every time in a for loop we write i++
But I want to increase i into 7 every time. I have given my code. Can anyone help me, please!!!

if (ddlMaintenPlan.SelectedItem.Text == "Weekly")
           {
               
               DateTime dtLastday = Convert.ToDateTime(dtpMaintenceEnd.Text.Trim());
               while (dsStartDate <= dtLastday)
               {
                   
                   for (int i = Convert.ToInt32(dsStartDate); i < Convert.ToInt32(dtLastday); i++)
                   {
                       dsStartDate = Convert.ToDateTime(Convert.ToInt32(dsStartDate) + Convert.ToInt32(i.ToString()));
                       DRLocal = DTLocal.NewRow();
                       DTLocal.Rows.Add(dsStartDate);
                   }
               }



           }

解决方案

for (int i = Convert.ToInt32(dsStartDate); i < Convert.ToInt32(dtLastday); i += 7)


这篇关于C Sharp for循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆