我有一个简单的自定义列表类,我正在尝试实现IComparable
它,但老实说它不起作用。我试过 MSDN 和其他博客,还是一样。
public class sortDateTime : IComparable
{
protected DateTime m_startDate, m_endDate;
public DateTime startDate
{
get { return m_startDate; }
set { m_startDate = startDate; }
}
public DateTime endDate
{
get { return m_endDate; }
set { m_endDate = endDate; }
}
public int CompareTo(object obj)
{
if(obj is sortDateTime)
sortDateTime sDT = (sortDateTime) obj; //here ERROR
return m_stDate.CompareTo(sDT.m_stDate);
}
}
遵循此示例,但收到错误:
嵌入语句不能是声明或标签语句