c#脚本实现一页展示4条数据
时间: 2024-04-08 07:28:50 浏览: 8
Sure! Here's an example of how you can implement a C# script to display four data items on a page:
```csharp
using System;
using System.Collections.Generic;
public class Program
{
public static void Main(string[] args)
{
// Sample data
List<string> dataItems = new List<string>()
{
"Data 1",
"Data 2",
"Data 3",
"Data 4",
"Data 5",
"Data 6",
"Data 7",
"Data 8"
};
int pageNumber = 1;
int itemsPerPage = 4;
// Calculate the starting index and ending index for the current page
int startIndex = (pageNumber - 1) * itemsPerPage;
int endIndex = Math.Min(startIndex + itemsPerPage, dataItems.Count);
// Display the data items for the current page
for (int i = startIndex; i < endIndex; i++)
{
Console.WriteLine(dataItems[i]);
}
}
}
```
In this example, we have a list of data items (`dataItems`) and we want to display four items per page. The `pageNumber` variable determines which page to display. The script calculates the starting and ending indexes based on the page number and the number of items per page. Finally, it uses a loop to display the data items for the current page.