I get the following error while trying to do a lexicographical sort of string
ERROR Message :”Count cannot be less than zero. Parameter name: count”
List<string> words = new List<string>();
words.Add("collin");
foreach (var word in words)
{
IEnumerable<string> sortedSubstrings =
Enumerable.Range(0, word.Trim().Length)
.Select(i => word.Substring(i))
.OrderBy(s => s.Length < 1 ? s : s.Remove(1, Math.Min(s.Length - 3, 3)));
}
I am trying to enhance this sort by skipping the 2nd,3rd and 4th character during the lexicographical sort process
What am I doing wrong?
Try making your .OrderBy line handle lengths less then 3 and make them 0. That’s where your exception is from.