类似这样一个foreach循环里:foreach(DataRow row in ds.Tables[].Rows)
{
  string str = row[0].ToString();
  if(str == ..)
  {
    continue;
  }
  else
  { 
    int i;
    Form2 f1 = new Form2(int i);
    f1.show()
  }
}假如全部循环完毕,不再跳入else里面
我想给出一个MessageBox信息
应该放在哪里啊?如果放在循环后,等show出Form2的时候它却弹出来了,这是不要得到的结果~
求助~

解决方案 »

  1.   

    在foreach前加一个标示:
    bool show = true;
    foreach(DataRow row in ds.Tables[].Rows)
    {
      string str = row[0].ToString();
      if(str == ..)
      {
        continue;
      }
      else
      {
        show=false;
        int i;
        Form2 f1 = new Form2(int i);
        f1.show()
      }

    if(show)
    {
        MessageBox.Show("信息");
    }
      

  2.   


    bool bFlag = false;
    foreach(DataRow row in ds.Tables[].Rows) 

      string str = row[0].ToString(); 
      if(str == ..) 
      { 
        continue; 
      } 
      else 
      { 
        bFlag =true;
        int i; 
        Form2 f1 = new Form2(int i); 
        f1.show() 
      } 

    if (bFlag=false)
    {
       MessageBox.Show("信息");
    }