davut temel davut temel - 1 month ago 14
ASP.NET (C#) Question

Skip and take method in List

I have a class

Players
. And I want to create
Hyperlink
with
Skip
and
Take
methods. But gives me
System.Linq.Enumerable
error. My goal is make a pyramid user list. here is my codes

public class Players
{
public string Name{ get; set; }
public int Order{ get; set; }
public int ID { get; set; }
}



List<Players> playerlist= new List<Players>();
playerlist= (from DataRow dr in dt.Rows
select new Players()
{
Name= (dr["name"].ToString()),
Order= int.Parse(dr["order"].ToString()),
ID = int.Parse(dr["Id"].ToString())

}).ToList();

playerlist= playerlist.OrderBy(x => x.Order).ToList();

int skip = 0;
int take = 1;
int addedCount = 0;

do
{

HyperLink links= new HyperLink();
links.Text = "" + playerlist.Skip(skip ).Take(take).Select(x => x.Name);
links.NavigateUrl = "playerdetails.aspx?id=" + oyunculistesi.Skip(skip).Take(take).Select(x => x.ID);
Page.Controls.Add(links);
addedCount += take ;
skip+= take ;
take += +1;

}
while (addedCount < playerlist.Count);


It is working with
StringBuilder
but with
HyperLink
not.

sb.AppendLine(string.Join(" ", players.Skip(skip).Take(take).Select(x => $"{x.Order}) {x.Name}")));

Answer Source

Your Select is returning an IEnumerable of char and you need to build a string from them by using string.Join like what you did in the stringbuilder:

linkuret.Text = string.Join("" , playerlist.Skip(skip).Take(take).Select(x => x.Name));