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

  • Home
  • SEARCH
  • 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 8047403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:05:04+00:00 2026-06-05T06:05:04+00:00

I have a class: public class ShipmentInformation { public string OuterNo { get; set;

  • 0

I have a class:

public class ShipmentInformation
{
    public string OuterNo { get; set; }
    public long Start { get; set; }
    public long End { get; set; }

}

I have a List<ShipmentInformation> variable called Results.

I then do:

List<ShipmentInformation> FinalResults = new List<ShipmentInformation>();
var OuterNumbers = Results.GroupBy(x => x.OuterNo);
foreach(var item in OuterNumbers)
{
   var orderedData = item.OrderBy(x => x.Start);

   ShipmentInformation shipment = new ShipmentInformation();
   shipment.OuterNo = item.Key;
   shipment.Start = orderedData.First().Start;
   shipment.End = orderedData.Last().End;

   FinalResults.Add(shipment);
}

The issue I have now is that within each grouped item I have various ShipmentInformation but the Start number may not be sequential by x. x can be 300 or 200 based on a incoming parameter. To illustrate I could have

  1. Start = 1, End = 300
  2. Start = 301, End = 600
  3. Start = 601, End = 900
  4. Start = 1201, End = 1500
  5. Start = 1501, End = 1800

Because I have this jump I cannot use the above loop to create an instance of ShipmentInformation and take the first and last item in orderedData to use their data to populate that instance.

I would like some way of identifying a jump by 300 or 200 and creating an instance of ShipmentInformation to add to FinalResults where the data is sequnetial.

Using the above example I would have 2 instances of ShipmentInformation with a Start of 1 and an End of 900 and another with a Start of 1201 and End of 1800

  • 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-06-05T06:05:06+00:00Added an answer on June 5, 2026 at 6:05 am

    Try the following:

    private static IEnumerable<ShipmentInformation> Compress(IEnumerable<ShipmentInformation> shipments) 
    {
      var orderedData = shipments.OrderBy(s => s.OuterNo).ThenBy(s => s.Start);
      using (var enumerator = orderedData.GetEnumerator())
      {
        ShipmentInformation compressed = null;
        while (enumerator.MoveNext())
        {
          var current = enumerator.Current;
          if (compressed == null) 
          {
            compressed = current;
            continue;
          }
          if (compressed.OuterNo != current.OuterNo || compressed.End < current.Start - 1)
          {
            yield return compressed;
            compressed = current;
            continue;
          }
          compressed.End = current.End;
        }
    
        if (compressed != null)
        {
          yield return compressed;
        }
      }
    }
    

    Useable like so:

    var finalResults = Results.SelectMany(Compress).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List<ShipmentInformation> public class ShipmentInformation { public string Type { get; set;
I have a class: public class CarList { public int quantity{get;set;} public List<Car> Cars
I have class: public class LoginResponse { public String SessionID { get; private set;
I have class Student { public List<Degree> Degrees {get;set;} } class Degree { public
I have a class public class ItemList { public long Id { get; set;
I have a class public class Setting<T> { public string name { get; set;
I have class Marker class Marker { public double Position {get; set;} public string
I have class public class Class2 { public string myName { get; set; }
I have class public class Chat { public string Ip { get; set; }
I have a class: public class Car { public string Model {get;set;} public string

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.