how to create this linq query -
i have situation have list of ids such {1,2,3,4}. need pass method list of ids , if list has same numbers in return true, else if either list not identical (disregarding ordering) need return false. so, call method {1,2,3,4,5} should return false while call {2,4,1,3} returns true. sounds simple enough can't figure out how it.
if guaranteed not have repeating elements in idlist
, can use following:
if (idlist.count == otheridlist.count && idlist.intersect(otheridlist).count() == idlist.count) { // contain same things. } else { // not contain same things. }
the first check make sure they're same size. cheap way see if lists have chance of being identical, same strings. also, without it, statement return true if otheridlist
superset of idlist
.
if cannot guarantee uniqueness within collection, think you're going have code yourself.
Comments
Post a Comment