我正在尝试编写一个类库,但是我收到以下错误: “'WorkMateLib.Login'类型的值无法转换为'WorkMateLib.Login'的一维数组'”
类的代码如下:
Public Class Logins
Public CurrentUser As Login()
Public Sub New()
CurrentUser = New Login()
End Sub
Public Function Authenticate(ByVal id As String, ByVal pw As String)
Dim adpt As New WorkMateDataSetTableAdapters.LoginsTableAdapter
For Each k As WorkMateDataSet.LoginsRow In adpt.GetDataByUserName(id)
If String.Equals(k.UserPW, pw) Then
CurrentUser = New Login(k.UserName, k.UserPW, k.UserType)
Return CurrentUser
Exit Function
End If
Next
CurrentUser = Nothing
Return Nothing
End Function
End Class
Public Class Login
Private _UserName As String
Private _UserPW As String
Private _UserType As String
Property UserName
Get
Return _UserName
End Get
Set(value)
_UserName = value
End Set
End Property
Property UserPW
Get
Return _UserPW
End Get
Set(value)
_UserPW = value
End Set
End Property
Property UserType
Get
Return _UserType
End Get
Set(value)
_UserType = value
End Set
End Property
Public Sub New()
UserName = ""
UserPW = ""
UserType = ""
End Sub
Public Sub New(ByVal Namee As String, ByVal pw As String, ByVal typee As String)
UserName = Namee
UserPW = pw
UserType = typee
End Sub
End Class
感谢您的帮助。
答案 0 :(得分:5)
应该只是
Dim CurrentUser as Login
将()
添加到Type的末尾会将其更改为Type的数组。
您应该将变量声明为
Dim CurrentUser As Login = New Login
因为这将实例化Login
对象的实例并将其分配给CurrentUser
变量。目前,您只是创建一个Login
类型的变量,但没有给它任何值。