I'm trying to group the strings according to their extension (last three characters) to train my LINQ skills (I'm a newbie), but I keep getting an exception:
System.ArgumentOutOfRangeException: 'Index and length must refer to a location within the string.
My code is bellow: Where is my mistake?
string[] files = new string[10] {"OKO.pdf","aaa.frx", "bbb.TXT", "xyz.dbf","abc.pdf", "aaaa.PDF","xyz.frt", "abc.xml", "ccc.txt", "zzz.txt"};
var res = from file in files
group file by file.Substring(file.IndexOf(".")+1,file.Length-1) into extensions
select extensions;
var res1 = files.GroupBy(file => file.Substring(file.IndexOf("."), file.Length - 1));
foreach(var group in res)
{
Console.WriteLine("There are {0} files with the {1} extension.", group.Count(), group.Key);
}