c# - see if any item exists in any list item -


i have list

        list<firstiterationcapacitors> firstiteration = new list<firstiterationcapacitors>(); // set of solution capacitors object 

here it's class

class firstiterationcapacitors     {         public int iteration { get; set; }         public int capacitoralocation { get; set; }         public int capacitorblocation { get; set; }         public int capacitorclocation { get; set; }     } 

now have second list

        list<possiblesolutioncapacitors> possiblesolution = new list<possiblesolutioncapacitors>(); // possible solution capacitors object 

here class

 class possiblesolutioncapacitors     {         public int capacitoralocation { get; set; }         public int capacitorblocation { get; set; }         public int capacitorclocation { get; set; }            } 

for given row (i.e row 2) in possiblesolution need see if

  1. possiblesolution.capacitoralocation not exist in firstiteration.capacitoralocation (that equal iteration x) or firstiteration.capacitorblocation (that equal iteration x) or firstiteration.capacitorclocation (that equal iteration x)

or

  1. possiblesolution.capacitorblocation not exist in firstiteration.capacitoralocation (that equal iteration x) or firstiteration.capacitorblocation (that equal iteration x) or firstiteration.capacitorclocation (that equal iteration x)

or

  1. possiblesolution.capacitorclocation not exist in firstiteration.capacitoralocation (that equal iteration x) or firstiteration.capacitorblocation (that equal iteration x) or firstiteration.capacitorclocation (that equal iteration x)

ideally boolean stating true false if condition true/false

here have tried far not working

int d = 4; // row care  int e = possiblesolution[d].capacitoralocation; int f = possiblesolution[d].capacitorblocation; int g = possiblesolution[d].capacitorclocation;    var fixedset = new hashset<int>() {e}; if (!firstiteration.any(x => fixedset.setequals(new[] { x.capacitoralocation, x.capacitorblocation, x.capacitorclocation }))) { fixedset = new hashset<int>() {f}; if (!firstiteration.any(x => fixedset.setequals(new[] { x.capacitoralocation, x.capacitorblocation, x.capacitorclocation }))) {  fixedset = new hashset<int>() {g}; if (!firstiteration.any(x => fixedset.setequals(new[] { x.capacitoralocation, x.capacitorblocation, x.capacitorclocation }))) {  //match not exist real work here ......  }  }  } 

thanks, damo

since in 3 of conditions check if particular location

does not exist in firstiteration.capacitoralocation or firstiteration.capacitorblocation or firstiteration.capacitorclocation

you can collect these locations in single set<int> quick check:

var firstiterationlocations = new hashset<int>(     firstiterationcapacitorlist     .where(loc => loc.iteration == x)     .selectmany(         loc => new[] {loc.capacitoralocation, loc.capacitorblocation, loc.capacitorclocation}     ) ); 

with firstiterationlocations in hand, can build condition follows:

if (!(firstiterationlocations.contains(possiblesolution[d].capacitoralocation) ||    firstiterationlocations.contains(possiblesolution[d].capacitorblocation) ||    firstiterationlocations.contains(possiblesolution[d].capacitorclocation)) ) {     ... } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -