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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
class LinqExercise
{
    static void Main(string[] args)
    {
 
        List<int> list = new List<int>();
        list.Add(10);
        list.Add(20);
        list.Add(30);
        list.Add(40);
        list.Add(90);
        list.Add(50);
        list.Add(70);
 
 
        Console.WriteLine("\nThe members of the list are : ");
        foreach (var lstnum in list)
        {
            Console.Write(lstnum + " ");
        }
        List<int> FilterList = list.FindAll(x => x > 20 ? true : false);
        Console.WriteLine("\n\nThe numbers greater than 20 are : ");
        foreach (var num in FilterList)
        {
            Console.WriteLine(num);
        }
        Console.ReadLine();
    }
}

Result

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

Leave a Comment