Using Linq to check if generic list in Dictionary contains a value -


how check if dictionary contains set of coordinates? using selectmanager , count still wrong. don't think checked values in the generic list.

i want iterate through matchtile , check every other elements in generic list condition (not part of question).

if meets condition, adds same group. when next iteration comes, should check if element has been added group. if yes, skips it. if not, creates new group (list).

can help?

private void groupmatches(list<int[]> matchtile){     dictionary<int, list<int[]>> groups = new dictionary<int, list<int[]>>();     int = 0;      foreach(int[] coord in matchtile){         var alreadycounted = groups.selectmany(x => x.value).where(x => x[0] == coord[0] && x[1] == coord[1]);          debug.log ("counted: " + alreadycounted.count ());          if(alreadycounted.count() > 0) continue;          // create new group         groups.add(i, new list<int[]>());            groups[i].add(coord);          foreach(int[] nextcoord in matchtile){             if (...)             {                 groups[i].add(nextcoord);                }         }          i++;     }         debug.log ("groups: " + groups.count); } 

try next code:

private void groupmatches(list<int[]> matchtile) {         dictionary<int, list<int[]>> groups           = matchtile.groupby(line => new{x = line[0], y = line[1]})                     .select((grp, index) => new{index, grp})                     .todictionary(info => info.index, info => info.grp.tolist());      debug.log("groups: " + groups.count); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -