Foreach loop, determine which is the last iteration of the loop

前端 未结 26 905
迷失自我
迷失自我 2020-11-28 02:56

I have a foreach loop and need to execute some logic when the last item is chosen from the List, e.g.:

 foreach (Item result in Mod         


        
26条回答
  •  一向
    一向 (楼主)
    2020-11-28 03:13

    foreach (DataRow drow in ds.Tables[0].Rows)
                {
                    cnt_sl1 = "
    " + "
    " + "
    "; cnt_sl2 = "
    " + "

    " + drow["situation_details"].ToString() + "

    " + "
    "; if (i == 0) { lblSituationName.Text = drow["situation"].ToString(); } if (drow["images_position"].ToString() == "0") { content += "
    " + cnt_sl1 + cnt_sl2 + "
    "; cnt_sl1 = ""; cnt_sl2 = ""; } else if (drow["images_position"].ToString() == "1") { content += "
    " + cnt_sl2 + cnt_sl1 + "
    "; cnt_sl1 = ""; cnt_sl2 = ""; } i++; }

提交回复
热议问题