/// <summary> /// The mode of the set of lengths of lines in a string. Whatever /// number occurs the most as length of characters in a line is returned. /// </summary> /// <returns>The line length that occurs the most.</returns> /// <param name="input">Input.</param> private int LengthMode(string input) { string[] lines = input.Split('\n'); var modes = new System.Collections.Generic.Dictionary <int, int>(); foreach (var line in lines) { if (modes.ContainsKey(line.Length)) { modes[line.Length] += 1; } else { modes[line.Length] = 1; } } return(modes.Aggregate(modes.First(), (a, b) => { if (b.Value > a.Value) { return b; } else { return a; } }).Key); }