c# - How can I transvers two collections to find out what objects are in one and not the other? -


i have following class:

 public objectivedetail()     public int objectivedetailid { get; set; }     public int number { get; set; }     public string text { get; set; }     public override bool equals(object obj)     {         return this.equals(obj objectivedetail);     }     public bool equals(objectivedetail other)     {         if (other == null)             return false;          return this.number.equals(other.number) &&             (                 this.text == other.text ||                 this.text != null &&                 this.text.equals(other.text)             );     }  } 

i have 2 icollection collections:

icollection<objectivedetail> _obj1; // reference icollection<objectivedetail> _obj2; // may have more, less or different objectdetails reference. 

the common field collections objectivedetailid. how can traverse collections for loop rows that:

  • are in _obj2 , not _obj1
  • are in _obj1 , not _obj2
  • are different between _obj1 , _obj2

note similar question asked earlier think bit simpler have added equals method.

you can use foreach

foreach(objectivedetail obj in _obj1) {     if (!(_obj2.contains(obj)))         //add list } 

just change logic in if statements , icollection rest of results.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -