TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
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
Forums
Monthly Leaders
Forum guidelines
Roy Guzman
NA
18
2.1k
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