Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Accept the members of a list and display the members more than a specific value

C# Sharp LINQ : Exercise-10 with Solution

Write a program in C# Sharp to accept the members of a list through the keyboard and display the members more than a specific value.

Sample Solution:-

C# Sharp Code:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  

class LinqExercise10 
    {  
        static void Main(string[] args)  
        {  
         int i=0;
		 int memlist,n,m;
            List<int> templist = new List<int>(); 
            Console.Write("\nLINQ : Accept the members of a list and display the members more than a specific value : "); 
            Console.Write("\n----------------------------------------------------------------------------------------\n");				
 
            Console.Write("Input the number of members on the List : ");  
            n= Convert.ToInt32(Console.ReadLine());             
            
                for(i=0;i<n;i++)
                {
                    Console.Write("Member {0} : ",i);  
                    memlist= Convert.ToInt32(Console.ReadLine()); 
                    templist.Add(memlist);
                }
            
            Console.Write("\nInput the value above you want to display the members of the List : ");  
            m = Convert.ToInt32(Console.ReadLine());     

            List<int> FilterList = templist.FindAll(x => x > m ? true : false);  
            Console.WriteLine("\nThe numbers greater than {0} are : ",m);
            foreach (var num in FilterList)  
            {  
                Console.WriteLine(num);  
            }  
   
            Console.ReadLine();  
        }  
    }
	

Sample Output:

LINQ : Accept the members of a list and display the members more than a specific value :                      
----------------------------------------------------------------------------------------                      
Input the number of members on the List : 5                                                                   
Member 0 : 10                                                                                                 
Member 1 : 20                                                                                                 
Member 2 : 30                                                                                                 
Member 3 : 40                                                                                                 
Member 4 : 50                                                                                                 

Input the value above you want to display the members of the List : 20                                        
  
The numbers greater than 20 are :                                                                             
30                                                                                                     
40                                                                                                     
50

Pictorial Presentation:

C# Sharp LINQ: Accept the members of a list and display the members more than a specific value.

Flowchart:

Flowchart: LINQ : Accept the members of a list and display the members more than a specific value

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to create a list of numbers and display the numbers greater than 80 as output.
Next: Write a program in C# Sharp to display the top nth records.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.