如何显示默认的构造字符串格式:你好,我的任务是写一个程序,显示格式为"月/日"使用默认构造函数的列表框和参数的控制。
我照顾了parameteriezed程序,但我有默认的构造函数的麻烦。
这里是Rectangle.vb
代码Public Class FormattedDate
Private _strMonth As String
Private _strDay As String
Public Sub New()
_strMonth = String.Empty
_strDay = String.Empty
End Sub
Public Sub New(ByVal Month As String,
ByVal Day As String)
_strMonth = Month
_strDay = Day
End Sub
Public Function GetDate() As String
Return _strMonth & "/" & _strDay
End Function
Public Property Month() As String
Get
Return _strMonth
End Get
Set(ByVal value As String)
Dim intMonth As Integer
Integer.TryParse(value, intMonth)
If intMonth < 1 OrElse intMonth > 12 Then
_strMonth = String.Empty
Else
_strMonth = value
End If
End Set
End Property
Public Property Day() As String
Get
Return _strDay
End Get
Set(ByVal value As String)
_strDay = value
End Set
End Property
End Class
这里的参数化程序的代码
{C}
下面是默认的构造过程中的代码,我无法得到链接到函数过程列表框中的月份和日期。
Private Sub btnDefault_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDefault.Click
Dim formatDate As New FormattedDate()
Dim Month As String
Dim Day As String
Month = lstMonth.SelectedItem.ToString
Day = lstDay.SelectedItem.ToString
lblHireDate.Text = formatDate.GetDate
End Sub
我在做什么错?我错过什么?
感谢。