将每个循环转换为for循环 [英] convert for each loop into for loop
本文介绍了将每个循环转换为for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将每个循环转换为For循环
protected void chkboxmaritalstatus_SelectedIndexChanged( object sender,EventArgs e)
{
int count = 0 ;
foreach (ListItem li in chkboxmaritalstatus.Items)
{
if (li.Selected)
count ++;
}
if (count > 3 )
{
rdomaritalstatusprefer.Checked = false ;
rdomaritalstatusprefernot.Checked = true ;
chkboxmaritalstatus.Enabled = false ;
chkboxmaritalstatus.ClearSelection();
}
}
i想要为循环中的每个循环代码执行此操作
解决方案
< blockquote>
for ( int i = 0 ; i < chkboxmaritalstatus.Items.Count; i ++)
{
if (chkboxmaritalstatus.Items [i] .Selected)
count ++;
}
protected void chkboxmaritalstatus_SelectedIndexChanged( object sender,EventArgs e)
{
int index = 0 ;
for ( int i = 0 ; i< chkboxmaritalstatus.items.count; i ++){
if (chkboxmaritalstatus.items [i] .Selected)
index ++;
}
if (index> 3){
rdomaritalstatusprefer.Checked = false < /跨度>;
rdomaritalstatusprefernot.Checked = true ;
chkboxmaritalstatus.Enabled = false ;
chkboxmaritalstatus.ClearSelection();
}
}
//希望您在寻找..
受保护 void chkboxmaritalstatus_SelectedIndexChanged( object sender,EventArgs e)
{
for ( int i = 0 ; i< chkboxmaritalstatus.items.count; i ++)>
{
if (chkboxmaritalstatus.items [i] .Selected&& i> 3)
{
rdomaritalstatusprefer.Checked = 假跨度>;
rdomaritalstatusprefernot.Checked = true ;
chkboxmaritalstatus.Enabled = false ;
chkboxmaritalstatus.ClearSelection();
}
}
}
//如果您的要求只是上述功能,请检查此项摘要。
<前一个=cs> 如果(chkboxmaritalstatus.GetSelectedIndices()。Count( )> 3 )
{
rdomaritalstatusprefer.Checked = 假跨度>;
rdomaritalstatusprefernot.Checked = true ;
chkboxmaritalstatus.Enabled = false ;
chkboxmaritalstatus.ClearSelection();
}
How to convert For Each loop into For loop
protected void chkboxmaritalstatus_SelectedIndexChanged(object sender, EventArgs e)
{
int count = 0;
foreach (ListItem li in chkboxmaritalstatus.Items)
{
if (li.Selected)
count++;
}
if (count > 3)
{
rdomaritalstatusprefer.Checked = false;
rdomaritalstatusprefernot.Checked = true;
chkboxmaritalstatus.Enabled = false;
chkboxmaritalstatus.ClearSelection();
}
}
i want this for each loop code in to for loop
解决方案
for (int i = 0; i < chkboxmaritalstatus.Items.Count; i++) { if(chkboxmaritalstatus.Items[i].Selected) count++; }
protected void chkboxmaritalstatus_SelectedIndexChanged(object sender, EventArgs e) { int index=0; for(int i=0;i<chkboxmaritalstatus.items.count;i++){ if (chkboxmaritalstatus.items[i].Selected) index++; } if(index>3){ rdomaritalstatusprefer.Checked = false; rdomaritalstatusprefernot.Checked = true; chkboxmaritalstatus.Enabled = false; chkboxmaritalstatus.ClearSelection(); } }
//hope you are looking for..
protected void chkboxmaritalstatus_SelectedIndexChanged(object sender, EventArgs e) { for(int i=0;i<chkboxmaritalstatus.items.count;i++)> { if (chkboxmaritalstatus.items[i].Selected && i>3) { rdomaritalstatusprefer.Checked = false; rdomaritalstatusprefernot.Checked = true; chkboxmaritalstatus.Enabled = false; chkboxmaritalstatus.ClearSelection(); } } }
// if your requirement is only the above functionality check this snippet.
if (chkboxmaritalstatus.GetSelectedIndices().Count() > 3) { rdomaritalstatusprefer.Checked = false; rdomaritalstatusprefernot.Checked = true; chkboxmaritalstatus.Enabled = false; chkboxmaritalstatus.ClearSelection(); }
这篇关于将每个循环转换为for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文