is there a way to set a variable to something at the end of foreach loop if condition not met in C#? -


foreach (objecta in alist()) {     foreach (objectb b in blist)     {         if (a.variable != b.variable1 && a.variable() != b.variable2)         {             a.setvariable("error");         }     } } 

the problem getting goes through foreach loop first time , sets variable error without checking if other values (when goes through loop again) finds match.

what wait until goes through lists , @ last foreach loop iteration if nothing in alist matches variable target && variable source in blist set error flag.

any suggestions around appreciated.

try doing other way around. search match instead of searching non-matches.

foreach (objecta in alist()) {     bool foundmatch = false;     foreach (objectb b in blist)     {         if (a.variable == b.variable1 || a.variable() == b.variable2)         {             foundmatch = true;             break;         }     }     if (!foundmatch)      {         a.setvariable("error");     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -