w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: LINQ : 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

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?



New Content: Composer: Dependency manager for PHP, R Programming