Q:

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

belongs to collection: All LINQ programs in C# with examples

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

The members of the list are : 

10 20 30 40 90 50 70 

The numbers greater than 20 are : 

30

40

90

50

70

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a program in C# to find the number of an arr... >>
<< Write a program in C# to display the name of the d...