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 LinqExercise11
{
static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list.Add(6);
list.Add(7);
list.Add(8);
list.Add(9);
list.Add(10);
Console.WriteLine("\nThe members of the list are : ");
foreach (var lstnum in list)
{
Console.WriteLine(lstnum + " ");
}
Console.Write("How many records you want to display? : ");
int num = Convert.ToInt32(Console.ReadLine());
list.Sort();
list.Reverse();
Console.Write("The top {0} records from the list are: \n", num);
foreach (int topn in list.Take(num))
{
Console.WriteLine(topn);
}
Console.ReadLine();
}
}
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.
Result:
The members of the list are :
1
2
3
4
5
6
7
8
9
10
How many records you want to display? : 5
The top 5 records from the list are:
10
9
8
7
6
need an explanation for this answer? contact us directly to get an explanation for this answer