Write a program in C# to create a list of numbers and display the numbers greater than 20 in LINQ Query


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class LinqExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. List<int> list = new List<int>();
  12. list.Add(10);
  13. list.Add(20);
  14. list.Add(30);
  15. list.Add(40);
  16. list.Add(90);
  17. list.Add(50);
  18. list.Add(70);
  19.  
  20.  
  21. Console.WriteLine("\nThe members of the list are : ");
  22. foreach (var lstnum in list)
  23. {
  24. Console.Write(lstnum + " ");
  25. }
  26. List<int> FilterList = list.FindAll(x => x > 20 ? true : false);
  27. Console.WriteLine("\n\nThe numbers greater than 20 are : ");
  28. foreach (var num in FilterList)
  29. {
  30. Console.WriteLine(num);
  31. }
  32. Console.ReadLine();
  33. }
  34. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts