top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to select top 5 records from List using LINQ in C#?

0 votes
447 views
How to select top 5 records from List using LINQ in C#?
posted May 12, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

namespace AbundantCode

{

internal class Program

{

//How to select top 5 records from List using LINQ in C# ?

private static void Main(string[] args)

{

List<string> Names = new List<string>();

Names.Add("Abundantcode");

Names.Add("Programming");

Names.Add("Websites");

Names.Add("Coding");

Names.Add("Technologies");

Names.Add("USA");

Names.Add("C#");

Names.Add(".NET");

var result = (from m in Names

select m).Take(5);

foreach(var item in result)

Console.WriteLine(item);

Console.ReadLine();

}

}

}
answer May 12, 2016 by Shivaranjini
...