sashomaga

Lambda FindAll()

Feb 25th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //finds all even numbers
  6. public static class Test
  7. {
  8.     static void Main()
  9.     {
  10.  
  11.         List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6 };
  12.  
  13.         List<int> evenNumbers = list.FindAll(x => (x % 2) == 0);
  14.  
  15.         foreach (var num in evenNumbers)
  16.         {
  17.  
  18.             Console.Write("{0} ", num);
  19.  
  20.         }
  21.  
  22.         Console.WriteLine();
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment