Split List(Of T into multiple List(Of T in a structure

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
Can LINQ do this? I have a List(Of T that holds 20 items. I want to split this list by said N amount, for example 10. My structure would hold a have a member of List(Of T that would hold each spitted section from the original List(Of T so that when the list is split the structure would contain 10 new List(Of T with each holding 2 values from the original list. The split of course must be in index order of the original list.

Hope that makes sense :D
 
Why would you want to do this in the first place? If you need to iterate through the list 10 items at a time, just do so from the original list, no need to split and copy and whatnot.

For GroupIndex = 0 To MyList.Count - 1 Step 10
    For ItemIndex = 0 To 9
        ' Do something with each item in each group
        DoSomething(MyList((GroupIndex * 10) + ItemIndex))
    Next
Next
 
Yes LINQ can do this. The Skip and Take methods are what you want. Use a loop with the counter as a page number, starting at zero. You Skip the page number multiplied by the page size and you take the page size. I won't be providing code because I've seen pretty much the exact same question at another forum so I'm guessing that it's an assignment of some sort.
 
Yes LINQ can do this. The Skip and Take methods are what you want. Use a loop with the counter as a page number, starting at zero. You Skip the page number multiplied by the page size and you take the page size. I won't be providing code because I've seen pretty much the exact same question at another forum so I'm guessing that it's an assignment of some sort.

Since when did school assignments use LINQ lol, I am not a member of any other forum let alone in school still. I'm 29 and a carpenter. Programming is for fun :) Will have a go and report back.
 
Since when did school assignments use LINQ lol, I am not a member of any other forum let alone in school still. I'm 29 and a carpenter. Programming is for fun :) Will have a go and report back.

So, the only possible place that anyone could learn programming in a formal setting is at high school? Maybe it's not an assignment but I prefer to err on the side of caution because, once you've helped someone cheat on their homework, you can't take it back. That has happened to me before and I see plenty of others do it all the time. Even if it's not homework, anyone should be able to take instructions and have a go, so I prefer to see everyone do that anyway. It's far more conducive to learning, whatever the context. Unlike carpentry, there's no mistake that can't be fixed. ;)
 
I don't think helping someone for a homework is such a bad thing, if it helps said person to understand better... However, of course, the question has to be somewhat articulated and show some semblant of knowing something. A question like "Wat iz the codes for doing this?????????????" will not get an answer from me. I understand what you are saying Jim, but one has to keep in mind that some people here are much more competent and better tutors than many official "teachers" around the world.
 
I don't think helping someone for a homework is such a bad thing, if it helps said person to understand better... However, of course, the question has to be somewhat articulated and show some semblant of knowing something. A question like "Wat iz the codes for doing this?????????????" will not get an answer from me. I understand what you are saying Jim, but one has to keep in mind that some people here are much more competent and better tutors than many official "teachers" around the world.

I've got no issue with helping people with homework either, but what I don't think is a good idea is just providing cut and paste code. In such cases, the recipient may well get good marks for that particular assignment, which is unfair to their classmates, but they will learn less, which does them no favours in the long run. It doesn't matter how inexperienced you are, if someone tells you what type(s) and member(s) to use then you're capable of searching for documentation and examples of their use. You're also capable of making an attempt to use that information. If that attempt fails then I am as happy as anyone to help fix it but, again, more with information than code to copy and paste. When it comes to homework assignments, I don't really care about the marks the person may get. The marks should be for their effort and work so that's their responsibility. I'm concerned about their learning something, and learning how to solve their own problems in the future is as important as solving the current problem on that count.
 
Back
Top