我怎样才能构建完美的条件

时间:2013-02-25 08:38:20

标签: c# if-statement

这是我的问题:我想创建一个程序来检查ATM中的错误,并将其与我的数据库中保存的数据进行比较,以获得具有每台机器的错误状态的SMS(已解决,未解决,新)。该程序已完成并且工作正常,但崩溃并在恢复后CompareErrs - 方法中的条件停止工作。正如它现在假设它将已解决的错误返回为新的。这是功能: - 请帮助条件:S

   private object[] CompareErrs(string MachineErr, string DBErr)        
    {
        #region CompareErrs
        object[] ToReturn = new object[2];

        string Errs_Solved = "";
        string Errs_UnSolved = "";
        string Errs_New = "";

        string[] MachineErrSplit = MachineErr.Split(' ');
        for (int i = 0; i < MachineErrSplit.Length; i++)
        {
            string Seperator = " ";
            //if (i == MachineErrSplit.Length - 1)
            //    Seperator = "";

            if (DBErr.Contains(MachineErrSplit[i]))
            {
                Errs_UnSolved += MachineErrSplit[i] + Seperator;
            }
            else //if (MachineErrSplit[i].Contains(DBErr))
            {
                Errs_Solved += MachineErrSplit[i] + Seperator;
            }

            if (!DBErr.Contains(MachineErrSplit[i]))
            {
                Errs_New += MachineErrSplit[i] + Seperator;
            }
        }

        ToReturn[0] = new string[3] { Errs_Solved, Errs_UnSolved, Errs_New };
        ToReturn[1] = MachineErr;
        return ToReturn;

        #endregion
    }

1 个答案:

答案 0 :(得分:1)

else //if (MachineErrSplit[i].Contains(DBErr))
{
     Errs_Solved += MachineErrSplit[i] + Seperator;
}

if (!DBErr.Contains(MachineErrSplit[i]))
{
     Errs_New += MachineErrSplit[i] + Seperator;
}

这两个是相同的......为不同的变量分配相同的值。

因为,

的条件
if (DBErr.Contains(MachineErrSplit[i]))

相同
if (!DBErr.Contains(MachineErrSplit[i]))