請問這段VB改成C#.NET 怎麼改?

If Label19.Caption = "" Then

datTemp = DTPicker2.Value

If (Year(datTemp) - 2000) < 10 Then

strYear = "0" + CStr(Year(datTemp) - 2000)

Else

strYear = CStr(Year(datTemp))

End If

If Month(datTemp) < 10 Then

strMonth = "0" + CStr(Month(datTemp))

Else

strMonth = CStr(Month(datTemp))

End If

If Day(datTemp) < 10 Then

strDay = "0" + CStr(Day(datTemp))

Else

strDay = CStr(Day(datTemp))

End If

1 Answer

Rating
  • x32768
    Lv 5
    1 decade ago
    Favorite Answer

    If (Label19.Caption == "")

    {

    datTemp = DTPicker2.Value;

    }

    If ((Year[datTemp] - 2000) < 10 )

    {

    strYear = "0" + Convert.ToString(Year[datTemp] - 2000);

    }

    Else

    {

    strYear = Convert.ToString(Year[datTemp]);

    }

    If (Month[datTemp] < 10)

    {

    strMonth = "0" + Convert.ToString(Month[datTemp]);

    }

    Else

    {

    strMonth = Convert.ToString(Month[datTemp]);

    }

    If (Day(datTemp) < 10)

    {

    strDay = "0" + Convert.ToString(Day(datTemp));

    }

    Else

    {

    strDay = Convert.ToString(Day[datTemp]);

    }

    2006-10-01 16:18:08 補充:

    倒數第八行改為 : If (Day[datTemp] < 10)

Still have questions? Get your answers by asking now.