If you want top 15
lines only, try Take (Linq) which is specially designed for this:
var lines = System.IO.File
.ReadLines(@"C:\Users\chri749y\Documents\Skrive til fil\Testprogram.txt")
.Take(15);
In case you want batch processing i.e. get 0 .. 14
lines then 15 .. 29
lines etc.
// Split input into batches with at most "size" items each
private static IEnumerable<T[]> Batch<T>(IEnumerable<T> lines, int size) {
List<T> batch = new List<T>(size);
foreach (var item in lines) {
if (batch.Count >= size) {
yield return batch.ToArray();
batch.Clear();
}
batch.Add(item);
}
if (batch.Count > 0) // tail, possibly incomplete batch
yield return batch.ToArray();
}
Then
var batches = Batch(System.IO.File
.ReadLines(@"C:\Users\chri749y\Documents\Skrive til fil\Testprogram.txt"),
15);
foreach (var batch in batches) { // Array with at most 15 items
foreach (var line in batch) {
...
}
}