我有一個簡單的自定義列表類,我想實現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);
}
}
其次this example,但得到的錯誤:
Embedded statement cannot be a declaration or labeled statement
我只想最新的(不是更早)開始日期 – user2262511 2013-04-11 10:41:01
它是怎麼在MSDN例如 – user2262511 2013-04-11 10:42:58
的http://計算器。com/questions/2496589/variable-declarations-following-if-statements – 2013-04-11 10:43:25