FindAll() Method in LINQ

Let us see a practical implementation for the FindAll() method in LINQ. We will create a list of numbers and out of this list we will try to display numbers greater than 100 as output. Let us see how we can achieve the same using FindAll() method in LINQ.

Write the following code in a console application.

  1. using System;  
  2. usingSystem.Collections.Generic;  
  3. usingSystem.Linq;  
  4. usingSystem.Text;  
  5. usingSystem.Threading.Tasks;  
  6.    
  7. namespaceFindAllMethod  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             List<int>mylist = new List<int>();  
  14.             mylist.Add(30);  
  15.             mylist.Add(400);  
  16.             mylist.Add(300);  
  17.             mylist.Add(90);  
  18.             mylist.Add(190);  
  19.             mylist.Add(787);  
  20.             mylist.Add(12);  
  21.    
  22.             List<int> _Lst = mylist.FindAll(a => a > 100 ? true : false);  
  23.             foreach (varnum in _Lst)  
  24.             {  
  25.                 Console.WriteLine(num);  
  26.             }  
  27.    
  28.             Console.ReadLine();  
  29.         }  
  30.     }  
  31. }  
Let us run the application and see the output.

output

So we have the numbers greater than 100 as the output. I hope this post is useful to developers.