我的班级成员“用户名”对于创建的所有“卖家”必须是唯一的吗?我可以在课堂上实现它还是主要实现它?两个类成员也不能为空或包含空格。我是否应该将所有对象存储在列表中,然后验证所述用户名是否已经存在?我很困惑我应该把它放在哪里。
Public Class Seller
Private _username As String
Private _password As String
Public Sub New(aname As String, apassword As String)
Me.Password = apassword
Me.UserName = anom
End Sub
Public Property Username As String
Get
Return _username
End Get
Set(value As String)
Dim test As String = value
test.Replace(" ", "")
test.Trim()
If (test <> value Or value = " ") Then
Throw (New ArgumentException("Username cannot be empty or contain spaces")
Else
_username = value
End If
End Set
End Property
Public Property Password As String
Get
Return _password
End Get
Set(value As String)
Dim test As String = value
test.Replace(" ", "")
test.Trim()
If (test <> value Or value = " ") Then
Throw (New ArgumentException("Password cannot be empty or contain spaces")
Else
_password = value
End If
End Set
End Property
End Class
谢谢