[C#高质量代码的建议]IComparable(Of T) 接口

有对象的地方就有比较:使用这个接口就可以通过Sort等排序了。

class Sample : IComparable<Sample>
{
     protected double m_value = 0.0;
     public int CompareTo(Sample sample)
{
    return m_value.CompareTo(sample.m_value);
}  
}

class Sample : IComparable
{
     protected double m_value = 0.0;
     public int CompareTo(object sample)
{
    Sample sa = sample as Sample;
    return m_value.CompareTo(sa .m_value);
}  
}


你可能感兴趣的:(object,C#,Class)