我需要驗證某個用戶是否存在於我的asp.net站點上。我想知道這兩個函數中的哪一個比其他哪個函數更高效,更快,更好,並且相互之間爲什麼。提前感謝!哪種功能更快更高效?
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
或
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
在不知道使用哪個成員資格提供者的情況下提出此類表現聲明爲時過早。 – Thorarin 2010-01-05 08:45:51
如果您的會員供應商沒有提供該級別的優化,您註定會失敗! :) – 2010-01-05 10:26:06