1. 程式人生 > >C#提示:並非所有的程式碼路徑都返回值

C#提示:並非所有的程式碼路徑都返回值

 public bool InsertTemp()
    {
        foreach (FileInfo FInfo in MyInfo)
        {
            XMLFillDataSet(FInfo);

            Rows1 = ds.Tables[0].Rows.Count;
            Rows2 = ds.Tables[1].Rows.Count;

            if (InsertTempYeWu() == false)
            {
                return false;
                break;
            }
            else
            {
                InsertTempYeWuMX();
                return true;
            }
        }  
    }

改正用下,即可通過編譯:

 public bool InsertTemp()
    {
        foreach (FileInfo FInfo in MyInfo)
        {
            XMLFillDataSet(FInfo);

            Rows1 = ds.Tables[0].Rows.Count;
            Rows2 = ds.Tables[1].Rows.Count;

            if (InsertTempYeWu() == false)
            {
                return false;
                break;
            }
            else
            {
                InsertTempYeWuMX();
                return true;
            }
        }
        return true;
      
    }