c# - Finding differences within 2 Lists of string arrays -


i looking find differences between 2 lists of string arrays using index 0 of array primary key.

list<string[]> original = new list<string[]>(); list<string[]> web = new list<string[]>();   //define arrays list 'original' string[] original_a1 = new string[3]{"a","2","3"}; string[] original_a2 = new string[3]{"x","2","3"}; string[] original_a3 = new string[3]{"c","2","3"};  //define arrays list 'web' string[] web_a1 = new string[3]{"a","2","3"}; string[] web_a2 = new string[3]{"b","2","3"}; string[] web_a3 = new string[3]{"c","2","3"};  //populate lists original.add(original_a1); original.add(original_a2); original.add(original_a3);  web.add(web_a1); web.add(web_a2); web.add(web_a3); 

my goal find in list 'original' not in 'web' using index 0 primary key
tried.

list<string> differences = new list<string>(); //differences go in here string tempdiff = ""; // use try , avoid duplicate entries not working  for(int = 0; < original.count; i++){  for(int j = 0; j< web.count; j++){      if(!(original[i][0].equals(web[j][0]))){       tempdiff = original[i][0];      }  }  differences.add(tempdiff); } 

output:

foreach(string x in differences){    console.writeline("size " + differences.count);    console.writeline(x);    console.readline(); }  size 3  size 3 x  size 3  x 

why reporting mismatch 3 times instead of once?

using linq can go:

var differences = orignal.except(web).tolist(); 

reference here

this give values in original, don't exist in web

sorry didn't read question properly, answer question: have nested for-loop. each value of original (3) loop through values of web (3), 9 loops total.

in 3 cases doesn't match , therefore outputs 3 times.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -