I Want to group Files by extensions. My FileDto looks like this:
public class FileDto
{
public string Extension { get; set; }
public string Filename { get; set; }
}
I want to do Dictionary (or any other collection) that will group my files by Extension (for example ".txt", ".doc") etc. I started to write some code:
// input.Files = IEnumerable<FileDto>
Dictionary<string, IEnumerable<FileDto>> dict = input.Files
.GroupBy(x => x.Extension) // i want to Extension by my key (list of txts, list of docs etc)
.ToDictionary(y => y.Key); // not working
foreach (var entry in dict)
{
// do something with collection of files
}
My question is, how to group list of objects by property?