Reputation: 21430
I have a list of all memberships:
Dim allUsers = Membership.GetAllUsers().Cast(Of MembershipUser).ToList
Despite my searches, I have been unable to figure out how to loop through this to do something like the following. I want to loop through and retrieve a record, if the record contains a certain value, add the user to a new collection.
for each allusers as user
' get user profile
' if user profile has a certain value, add it to another collection
end for each
Then, once the new collection is full, output that collection to my view.
Does that make sense? How can I do this? Thank you.
Upvotes: 4
Views: 2140
Reputation: 61
Added C# version:
var newListOfUsers = new List<MembershipUser>();
Membership.GetAllUsers().OfType<MembershipUser>().ToList().ForEach( user =>
{
if(user.Comment.Equals("A Leather Glove")) newListOfUsers.Add(user);
});
Upvotes: 4
Reputation: 6607
Try this:
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
Upvotes: 4