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.
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Text;
- usingSystem.Threading.Tasks;
-
- namespaceFindAllMethod
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int>mylist = new List<int>();
- mylist.Add(30);
- mylist.Add(400);
- mylist.Add(300);
- mylist.Add(90);
- mylist.Add(190);
- mylist.Add(787);
- mylist.Add(12);
-
- List<int> _Lst = mylist.FindAll(a => a > 100 ? true : false);
- foreach (varnum in _Lst)
- {
- Console.WriteLine(num);
- }
-
- Console.ReadLine();
- }
- }
- }
Let us run the application and see the output.
So we have the numbers greater than 100 as the output. I hope this post is useful to developers.