Geom dev Geom dev - 3 years ago 94
C# Question

c# comparing two lists of integers in c#

I have two lists that is

List<int> comments ;
List<int> no_checks;

Now i would like to see if all no_checks have comments. So during my processing of data whenever a comment is added am adding its id to comment list and when a no radio is selected am adding its id to no_checks

So a sample output to console has


below should return false;
comment=[12, 13,15]
no_checks = [12,13,15,17 ] //one no has no comment


below should return true
comment=[12, 13,15]
no_checks = [12,13 ] //all have comments

So am stuck here

public bool allnoHaveComments(){
var allhave=true;

for(var i=0; i<no_checks.count; i++){
//if one no_checks is not contained in comments allhave=false

return allhave;

How can i proceed to compare and check to see that id's in no_checks are all contained in comments else if they are not return false

How can i go about this

Answer Source
bool isallnoHaveComments= !no_checks.Except(comment).Any();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download