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
Brian Dahl
NA
9
19.8k
Split a list into sub-lists taking
Jul 6 2018 3:00 AM
Hi i have the following Problem. I have a list and i want to divide the List into sub-lists dependend from a value from a cell.
For Example:
I have a List<DataRow> and in the column "Name" from every DataRow start the Sublist with the value "Start" and end it with "End".
I have solved it with the following code, but i want to know if there is a more efficent way to solve it?
var rowsFromTable = table.AsEnumerable().ToList();
List<List<DataRow>> chunks =
new
List<List<DataRow>>();
IEnumerable<DataRow> rest;
do
{
rest = rowsFromTable.Except(chunks.SelectMany(c => c));
var extractRows = rest.TakeWhile((row, index) => (
string
)row[
"Name"
] !=
"Start"
|| index == 0).ToList();
chunks.Add(extractRows);
}
while
(rest.Any());
Best Regards
Brian Dahl
Reply
Answers (
1
)
Left Outer Join Using Linq
anyone convert this sql query to linq