Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Find the number that don't exist in another array
  2. A = {1,2,3,4,5,6,7,8,9,10}
  3.  
  4. B = {1,2,3,7,8}
  5.  
  6. result = {4,5,6,9,10}
  7.        
  8. var C = A.Except(B);
  9.        
  10. int[] C = A.Except(B).ToArray();
  11.        
  12. var arrayA = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  13.  
  14. var arrayB = new [] { 1, 2, 3, 7, 8 };
  15.  
  16. var result = arrayA.Except(arrayB);
  17.        
  18. public void Linq52()
  19. {
  20.     int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
  21.     int[] numbersB = { 1, 3, 5, 7, 8 };
  22.  
  23.     IEnumerable<int> aOnlyNumbers = numbersA.Except(numbersB);
  24.  
  25.     Console.WriteLine("Numbers in first array but not second array:");
  26.     foreach (var n in aOnlyNumbers)
  27.     {
  28.         Console.WriteLine(n);
  29.     }
  30. }