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

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 1.25 KB  |  hits: 14  |  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. c# Find an item in 2 / multiple lists
  2. private static IEnumerable<TSource> ConcatIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
  3. {
  4.     foreach (TSource iteratorVariable0 in first)
  5.     {
  6.         yield return iteratorVariable0;
  7.     }
  8.     foreach (TSource iteratorVariable1 in second)
  9.     {
  10.         yield return iteratorVariable1;
  11.     }
  12. }
  13.        
  14. IEnumerable<string> concatenated = new[] { firstColl, secondColl }
  15.     .SelectMany(item => item);
  16.        
  17. var query = list1.Concat(list2).Where(x => x.Category=="my category");
  18.        
  19. var matched = list1.Concat(list2).FirstOrDefault(e => element.Equals(e));
  20.        
  21. BaseType matched = list1.Concat(list2).Concat(list3).FirstOrDefault(e => element.Equals(e));
  22.        
  23. var list1 = new List<int>{1,2,3,4,5,6,7};
  24. var list2 = new List<int>{0,-3,-4,2};
  25.  
  26. int elementToPush = 4;//value to find among available lists
  27.  
  28. var exist = list1.Exists(i=>i==elementToPush) || list2.Exists(j=>j==elementToPush);
  29.        
  30. List<string> a = new List<string>{"apple", "aardvark"};
  31. List<string> b = new List<string>{"banana", "bananananana", "bat"};
  32. List<string> c = new List<string>{"cat", "canary"};
  33. List<string> d = new List<string>{"dog", "decision"};
  34.  
  35. List<List<string>> super = new List<List<string>> {a,b,c,d};
  36.  
  37. super.Any(x=>x.Contains("apple"));