34
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
5
public class PaginationExample
6
{
7
public static void Main()
8
{
9
// Sample data
10
List<string> items = new List<string>
11
{
12
"Item1", "Item2", "Item3", "Item4", "Item5",
13
"Item6", "Item7", "Item8", "Item9", "Item10"
14
};
15
16
int currentPage = 1;
17
int pageSize = 3;
18
19
// Get data for the current page
20
List<string> pagedItems = GetPagedData(items, currentPage, pageSize);
21
22
// Display paged items
23
Console.WriteLine($"Page {currentPage}:");
24
foreach (string item in pagedItems)
25
{
26
Console.WriteLine(item);
27
}
28
}
29
30
public static List<T> GetPagedData<T>(List<T> source, int page, int pageSize)
31
{
32
return source.Skip((page - 1) * pageSize).Take(pageSize).ToList();
33
}
34
}
Cached Result