我为什么得到:'System.Collections.IEnumerable'没有类型参数,所以不能有类型参数?

时间:2016-01-27 15:19:29

标签: asp.net vb.net passwords ienumerable credentials

这是我的简单用户名和密码登录,可以将用户重定向到其他“会员区”页面。

但是我得到了:

BC32045:'System.Collections.IEnumerable'没有类型参数,所以不能有类型参数

我不知道为什么。

有人可以帮忙吗?

谢谢大卫。

Public Class MyPage
Inherits Page
Private Structure Cred
    Public Username As String
    Public Password As String
    Public RedirectUrl As String
    Public Sub New(un As String, pw As String, Optional ru As String = "/admin/default.aspx")
        Username = un
        Password = pw
        RedirectUrl = ru
    End Sub
End Structure

Private ReadOnly _credentials As IEnumerable(Of Cred) = New () {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo"), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}

Public Sub Page_Load(sender As Object, e As EventArgs)
    Dim user = _credentials.SingleOrDefault(Function(x) x.Username = UserName.Text AndAlso x.Password = Password.Text)
    If user IsNot Nothing Then
        Session("Admin") = True
        Response.Redirect(user.RedirectUrl)
    Else
        Session("Admin") = False
        LtlLogin.Text = "<p>Sorry, you have provided incorrect login details.</p>"
    End If
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我得到“类型预期”编译器错误,这是正确的。删除select count(distinct(a.mat)),count(distinct(c.mail)) as nb from aca as a left join c on c.mat=a.mat group by a.mat order by nb desc where nb > 0; ,然后替换

New()

Private ReadOnly _credentials As IEnumerable(Of Cred) = New () {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo"), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}

或使用Private ReadOnly _credentials As IEnumerable(Of Cred) = {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo"), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}

但是,您应该使用类而不是结构。使用New Cred(){...},您无法使用Option Strict,因为If user IsNot NothingCred,因此是值类型。