I get the following error, and I can’t understand why and how to overcome it (or implement icomparable).
I am trying to get the Group property from an object that has the most groups using Max ().
public class Program
{
private static void Main(string[] args) {
var list = new List<Foo>();
for (var i = 0; i < 10; i++) {
list.Add(new Foo());
if (i == 5) {
var foo = new Foo() {
Group = { "One", "Two", "Three" }
};
list.Add(foo);
}
}
var maxGroup = list.Max(x => x.Group);
}
}
public class Foo {
public Guid Id { get; } = new Guid();
public int Field1 { get; set; }
public int Field2 { get; set; }
public int Field3 { get; set; }
public int Field4 { get; set; }
public List<string> Group { get; set; } = new List<string>();
}
at least one object must implement icomparable
source
share