Home > Net >  C# 2 List doesn't match
C# 2 List doesn't match

Time:12-28

List<Object> rollerliste = (from row in roller.AsEnumerable() select (row["rolName"])).ToList();
List<Object> yetkiliste  = (from row in roller.AsEnumerable() select (row["Visible"])).ToList();
                    
for(int r = 0; r < rollerliste.Count(); r  )
{
    for (int y = 0; y < yetkiliste.Count(); y  )
    {
         if(rollerliste[r].ToString() == "frmMasalar" && yetkiliste[y].ToString() == "true" && r == y)
         {
             cu.frmMasalar = 1;
         }
         else
         {
             cu.frmMasalar = 0;
         }
    }
}

Actually if(rollerliste[r].ToString() == "frmMasalar" && yetkiliste[y].ToString() == "true" && r == y) it seems to be checking for correct data but not working.

rollerliste yetkiliste
frmMasalar True
frmYonetim True

I just want to make check rollerliste if column1 is true "button.Enable = true" or false

CodePudding user response:

Please note that, within your loops, you are overwriting cu.frmMasalar over and over again. That alone might be the reason you're not getting what you want.

I'm not sure I totally understand what you want to do. But, check whether this might be simpler:

cu.frmMasalar = 0;
foreach(var row in roller.AsEnumerable()) {
  if((string) row["rolName"] == "frmMasalar" && (bool) row["Visible]) {
    cu.frmMasalar = 1;
    break;
  }
}

There are also more condensed ways to do this, if the point is to find the one entry where rolName == "frmMasalar":

cu.frmMasalar = 0;
var matchingRow = roller.AsEnumerable()
                        .FirstOrDefault(r => (string) r["rolName"] == "frmMasalar" 
                                             && (bool) row["Visible"]);
if(matchingRow != null)
   cu.frmMasalar = 1;
  • Related