/// <summary> /// Reduces the number of rows, based on the entries inside rows parameter. /// E.g. rows = { "Insert", "Day", "Of", "Week", "Here" }, maxRows == 3 /// Result { "Insert", "Day", "Of Week Here" } /// </summary> /// <param name="rows">Incoming rows</param> /// <param name="maxRows">Max number of rows</param> internal static IEnumerable<string> ReduceRowCount(List<string> rows, int maxRows) { if (rows == null || maxRows <= 0) throw new ArgumentException(); var results = new List<string>(); foreach (var row in rows) { // There are still room in the results list. if (results.Count < maxRows) { results.Add(row); continue; } // Already full, keep appending to last row. var lastRow = results.Last(); results.Remove(lastRow); results.Add(lastRow + " " + row); } return results; }