我列出了所有会员资格:
Dim allUsers = Membership.GetAllUsers().Cast(Of MembershipUser).ToList
尽管我进行了搜索,但我一直无法弄清楚如何循环执行此操作以执行以下操作。我想循环并检索记录,如果记录包含特定值,则将用户添加到新集合。
for each allusers as user
' get user profile
' if user profile has a certain value, add it to another collection
end for each
然后,一旦新集合已满,请将该集合输出到我的视图中。
这有意义吗?我怎样才能做到这一点?谢谢。
答案 0 :(得分:4)
试试这个:
Public Function GetUsers() As IEnumerable(Of MembershipUser)
Dim newListOfUsers = New List(Of MembershipUser)()
Dim users As MembershipUserCollection = Membership.GetAllUsers()
For Each user As MembershipUser In users
If user.Comment = "A Leather Glove" Then
newListOfUsers.Add(user)
End If
Next
Return newListOfUsers
End Function
答案 1 :(得分:3)
添加了C#版本:
var newListOfUsers = new List<MembershipUser>();
Membership.GetAllUsers().OfType<MembershipUser>().ToList().ForEach( user =>
{
if(user.Comment.Equals("A Leather Glove")) newListOfUsers.Add(user);
});