C#关于遍历返回值如何写

下面是个BOOL类型的函数,不知该如何写
private bool JCode(string SID, string str)
{
bool B ;
DataTable Ruledt = dtRule(Comm.Workid, Comm.Proid);
DataTable R_S1 = newdt(SID, Ruledt);
for(int i=0;i<R_S1.Rows.Count;i++)
{
int type = (int)R_S1.Rows[i]["R_type"];
if (type == 1)
{
int S = (int)R_S1.Rows[i]["codeS"];
int E = (int)R_S1.Rows[i]["codeE"];
string Str= (string)R_S1.Rows[i]["Rulestring"];
if(Str!=str.Substring(S-1,E-S+1))
{
B = false;
break;
}
else
{
B=true;
}

            }
            if (type == 2)
            {
                int S = (int)R_S1.Rows[i]["Rstart"];
                int E = (int)R_S1.Rows[i]["Rend"];
                if (S < (Convert.ToInt32(str.Substring(S - 1, E - S + 1))) && (Convert.ToInt32(str.Substring(S - 1, E - S + 1))) > E)
                {
                    B = false;
                }
                else
                {
                    B = true;
                }

            }

        } 
        return B;
    }

用 foreach 嵌套 if判断 这个应该比较简单

Foreach 实现遍历 在遍历出每一项时 用 if去执行判断就好了

private bool JCode(string SID, string str)
{
bool B ;
DataTable Ruledt = dtRule(Comm.Workid, Comm.Proid);
DataTable R_S1 = newdt(SID, Ruledt);
for(int i=0;i<R_S1.Rows.Count;i++)
{
int type = (int)R_S1.Rows[i]["R_type"];
if (type == 1)
{
int S = (int)R_S1.Rows[i]["codeS"];
int E = (int)R_S1.Rows[i]["codeE"];
string Str= (string)R_S1.Rows[i]["Rulestring"];
if(Str!=str.Substring(S-1,E-S+1))
{
B = false;
break;
}
else
{
B=true;
}

            }
            if (type == 2)
            {
                int S = (int)R_S1.Rows[i]["Rstart"];
                int E = (int)R_S1.Rows[i]["Rend"];
                if (S < (Convert.ToInt32(str.Substring(S - 1, E - S + 1))) && (Convert.ToInt32(str.Substring(S - 1, E - S + 1))) > E)
                {
                    B = false;
                }
                else
                {
                    B = true;
                }

            }

        } 
        return B;
    }

上面是详细代码!!!

请看我的详细代码
意思是在DT里面遍历,按条件判断,并返回这个判断值(BOOL型)