vb.net如何用property禁止不合法的赋值
如题,不是通过如下的msgbox,而是在编码时就提示错误,让其不能编译成功,有提示,跟系统类型一样的
Property datBREAKFAST_BEGIN() As Date
Get
Return _datBREAKFAST_BEGIN
End Get
Set(ByVal value As Date)
If value < Convert.ToDateTime(value.ToShortDateString + " 04:00:01") Or value > Convert.ToDateTime(value.ToShortDateString + " 10:00:00") Then
_datBREAKFAST_BEGIN = Convert.ToDateTime(value.ToShortDateString + " 04:00:01")
MsgBox("早餐的赋值不在规定的范围内", MsgBoxStyle.Exclamation, "")
Exit Property
Else
_datBREAKFAST_BEGIN = value
End If
End Set
End Property