Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:31:06+00:00 2026-05-26T15:31:06+00:00

I have an array List<SomeObject> which contain ascending order of dates (and some more

  • 0

I have an array List<SomeObject> which contain ascending order of dates (and some more fields with info). The list will be Grouped into a List<List<SomeObject>>, which correlate to my subject.

One List<SomeObject> groups into an List<List<SomeObject>>. In this former case only contain 1 row.

Some calculations occurs on LastOrDefault and FirstOrDefault of that row. (In the end, the method return one SomeObject with a date, type and calculated value).

List<List<SomeObject>> Array; // Should be filled with the grouped List<SomeObject>

List<SomeObject>              // One SomeObject is a row below,
2011-01-01   enumType.Ok        140.0
2011-01-02   enumType.Ok        210.0
2011-01-03   enumType.Ok        250.0
2011-01-04   enumType.Blocking  310.0
2011-01-05   enumType.Ok        4.0
2011-01-06   enumType.Ok        34.0
2011-01-07   enumType.Ok        93.0
and counting..

Each row in the array have a type (enum) which normally are “Ok”.
This array can have occurences of “NotOk” instead of “Ok” (simplified description).

So, the question is,
The row 2011-01-05 have NotOk, which must split the array. The result will be as below. All rows up to the Blocking in one array, then next array for the rest of the rows (or to next point of “blocking”.

List<SomeObject>
2011-01-01   enumType.Ok        140.0
2011-01-02   enumType.Ok        210.0
2011-01-03   enumType.Ok        250.0
2011-01-04   enumType.Blocking  310.0

List<SomeObject>
2011-01-05   enumType.Ok        4.0
2011-01-06   enumType.Ok        34.0
2011-01-07   enumType.Ok        93.0
and counting..   

Then I can do a separate groupby/calculate sum on each list and lastly sum each groupby together.

[Edit]
I was helped by the answer from BrokenGlass, which worked exactly as stated. Though, I did a typo in my question that change the behavior of his answer. The first item in next array should be AFTER .Blocking. Just take his currentList.Add(item); before the if(currentList.Count – clause and the answer are still correct. Please also mind that this extension should be done only if needed, because we’re miss the point of my Q every time it need looping each value because of “Blocking”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:31:07+00:00Added an answer on May 26, 2026 at 3:31 pm

    You could just write a simple extension method to split up your single list into an enumeration of lists, each containing at least one item and split at any item with state NotOk:

    public static class MyExtensions
    {
        public static IEnumerable<List<SomeClass>> Split(this IEnumerable<SomeClass> source)
        {
            List<SomeClass> currentList = new List<SomeClass>();
            foreach (var item in source)
            {
                if(currentList.Count > 0 && item.State == States.NotOk)
                {
                    yield return currentList;
                    currentList = new List<SomeClass>();
                }
                currentList.Add(item);
            }
    
            if (currentList.Count > 0)
                yield return currentList;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have an array list which has some numbers in it like {23,16,45,26,2,5,9}
I have an array which is a list of domains, I want to print
I have an array that contains a list of vertices which I copy to
I have an array list that could contain component or composite and each component
I have a array list which have a list of a type, but all
I have an Array list of a custom class which is essentially has two
Suppose I have a method that returns an array or list or some other
I have an array-list that contains some UserID. I need a query like this:
I have some problem to compare values from different array list From this values,
how to compare value in an array? I have array named list which contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.