Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Roy Guzman
2.2k
18
1.7k
find the item in a list of lists. I am struggling
Jul 17 2017 9:18 AM
I have a list of strings list and a number pageSize and pageNumber and a rowNumber, I want to split the list by the page size and creat a slit of lists, then return the element given at pageNumber and rowNumber. if the pageNumber and the rowNumber are above the possible index level, then a null value must be returned. both the pageNumber and the rowNumber are zero-based indexes
exmaple list = [1,2,3,4,5,6,7,8,9,10] pageSize = 3, pageNumber = 2 rowNumber = 1 Result:List = [[1.2.3].[4,5,6],[7,8,9], [10]] and the correct value is 8
i have made many attempts but this one was the nearest
public static int? GetItemInThePagedDataList(IEnumerable<int> list, int pageSize, int pageNumber, int rowNumber)
{
var lists = list.chop(pageSize);
if(pageNumber >=lists.count() || rowNumber >= lists.first().count())
throw new ArgumentOutofReachException();
return lists.elementAt(pageNumber).ElementAt(rowNumer);
}
Reply
Answers (
4
)
how to copy text from a text file then write it in a batch
How to stop FOREACH loop without breaking out of the loop