You can use SkipWhile
and TakeWhile
methods
aCopyOfRecords
.SkipWhile(x => x != record)
.Skip(1)
.TakeWhile(x => x.InnerText.StartsWith("Y"));
This will give you the Y
records that comes after specific record that starts with X
.In order to get count, just use Count
.If you want to insert new items to your list, use List<T>.Insert
method:
var count = aCopyOfRecords
.SkipWhile(x => x != record)
.Skip(1)
.TakeWhile(x => x.InnerText.StartsWith("Y"))
.Count();
aCopyOfRecords.Insert(aCopyOfRecords.IndexOf(record) + count, newItem);