The problem is not the Person class, it's the type of PersonId: if it's integer, that'll work fine:
class Program
{
static void Main(string[] args)
{
var list = new List<Person>();
list.Add(new Person(){PersonId = 3});
list.Add(new Person(){PersonId = 7});
list.Add(new Person(){PersonId = 9});
list.Add(new Person(){PersonId = 42});
var newlist = list.OrderByDescending(x => x.PersonId).ToList();
Console.ReadLine();
}
}
class Person
{
public int PersonId {get; set; }
}
But if the PersonId isn't IComparable there is no real way to be sure that the ordering is correct, other than arranging a comparator. But you won't get an error even like this:
class Program
{
static void Main(string[] args)
{
var list = new List<Person>();
list.Add(new Person(){PersonId = 3});
list.Add(new Person(){PersonId = 7});
list.Add(new Person(){PersonId = 9});
list.Add(new Person(){PersonId = 42});
var newlist = list.OrderByDescending(x => x.p).ToList();
Console.ReadLine();
}
}
class Person
{
public int PersonId {get; set; }
public Person p { get; set; }
}
}
You'll just get the same order you started with, probably.