I”ve got a List<Foo>. Foo class contains a Type property. Type property is a enum.
public enum Type
{
Arithmetic, Fraction, ...
}
public class Foo
{
public Type ProblemType
{
get; set;
}
}
I’d like to generate another list where it is sorted by ProblemType, and each one contains Foo clases which belong to the same Type. I can imagine I should use Enumerable, but I don’t know how use them.
Thanks in advance
You can use GroupBy() to do that:
In passing, I would advise against using
Typeas the name of your enum, as getting into name conflicts with System.Type is usually not a good idea. You can even name itProblemType, since writingpublic ProblemType ProblemType { get; set; }is unambiguous.