public class Witness
{
public Mobile m_mobile;
public bool m_hasLOS;
public double m_distanceToSqrt;
public Witness(Mobile m, bool hasLOS, double distanceToSqrt)
{
m_mobile = m;
m_hasLOS = hasLOS;
m_distanceToSqrt = distanceToSqrt;
}
}
I've created a list of these objects 'witnesses' and now want to sort it on both m_hasLOS and m_distanceToSqrt.
In my code I call:
List<Witness> sorted = witnesses.OrderBy(x => x.m_hasLOS).ThenBy(x => x.m_distanceToSqrt).ToList();
This works, but the list is not ordered how I would like. How do I change the ordering such that: LOS is always at the top of the list, ordered on ascending distance? And where LOS is false, the list is then just ascending distance?
For example:
o1: m_LOS = true, m_distanceToSqrt = 13
o2: m_LOS = false, m_distanceToSqrt = 6
o3: m_LOS = false, m_distanceToSqrt = 2
Should yield the reaultant sort:
o1: m_LOS = true, m_distanceToSqrt = 13
o3: m_LOS = false, m_distanceToSqrt = 2
o2: m_LOS = false, m_distanceToSqrt = 6