merge multiple generic list reocrds into one on condition C#

78 Views Asked by At

I had a task where i've to add new record after comparing previous one

Ex. there are Layers 1,2,3,... in this

layer 1 have records like this

enter image description here

Now I can add records of layer 2 only if it start and end is within Layer 1s start end

I created a simple < && > logic it worked. But then new case arrives that if layer 1 contains sequential records then it should be treated as one record first like this

enter image description here

As records are not necessarily needed to add in a sequence of Start-End then the first end is seconds Start, I'm unable to use Min Max.

Please any suggestion to merge those list records...

foreach (var item in prevCompleteAct)
{
   if ((_start >= item.Start&& _start <= item.End)&& (_end >= item.Start&& _end <= item.End))
   {
        res = "ok";
        break;
   }                                    
}

This is not actual records, the tables shown are just a simplified portion for understanding

A general line example how records get inserts before are

  1. there is a line consider is of 100m, where the user split it into 10m brackets,
  2. Now a user has to apply layers of different colors on it which is in layer sequence. a user add layer 1 from 00 to 10 then 10 to 20 and skip 20 to 30 as there was a difficulty and continue with 30 to 50 and so on, so it's not like user has to paint layer 1 sequentially but it is mandatory to done all line means 00 to 100m for layer 1.

  3. Now the additional condition is when he starts to apply layer 2 for eg. 00 to 20 then it's mandatory that layer 1's 00 to20 must be done before

Update

thank you @DragandDrop, https://dotnetfiddle.net/4Q6Pyb given by you is helpful!

0

There are 0 best solutions below