I need to verify if a certain user exist on my asp.net site.I want to know if which of these two functions is more efficient, faster and better compared to each other and why.Thanks in advance!
Public Function CheckIfFriendExist(ByVal arg As String) As Boolean
Dim alluser As New MembershipUserCollection()
alluser = Membership.GetAllUsers()
For Each user As MembershipUser In alluser
If user.UserName.ToLower() = arg.ToLower() Then
Return True
Exit For
End If
Next
Return False
End Function
or
Public Function CheckIFFriendExist2(ByVal arg As String) As Boolean
Dim x As Integer = 0
Dim themember As MembershipUserCollection = Membership.FindUsersByName(arg, 0, 1, 1)
For Each member As MembershipUser In themember
x = x + 1
Next
If x > 0 Then
Return True
Else
Return False
End If
End Function