Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 521221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:13:40+00:00 2026-05-13T08:13:40+00:00

I need to verify if a certain user exist on my asp.net site.I want

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:13:40+00:00Added an answer on May 13, 2026 at 8:13 am

    Generally speaking, the second option has the better potential for performance. The actual effect depends on which membership provider you are using, but in the second case any implementation can take advantage of any internal indexing mechanisms if they are present, and potentially less data needs to be retrieved and transferred because you’re only getting at most one MembershipUser due to the paging.

    Theoretically, the first option could be faster than the second, but that would mean the membership provider implementation really sucks 🙂

    You appear to be counting the number of members in the collection, but you merely need to know if there is at least one member in the collection. Thus counting is not actually necessary. Also, what is wrong with using the Count property? I’m not saying this for optimization purposes since the impact will be minimal, but I think the intent of your code would be clearer if written that way.

    Public Function CheckIFFriendExist2(ByVal arg As String) As Boolean
        Dim foundMembers As MembershipUserCollection = _
            Membership.FindUsersByName(arg, 0, 1, 1)
    
        Return foundMembers.Count > 0
    End Function
    

    Alternatively, use Membership.GetUser to retrieve a single user by name. After all, I wouldn’t recommend implementing a membership provider that allows for multiple users with the same name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to verify that asp.net and c#.net web forms are different or same.
I have a string which I need to verify if it's a Country code.
I will be taking URL from user. Now I need to verify whether address
I will soon need to add SSO to an ASP.NET app using SAML. The
I need to verify using Selenium (or similar framework) that certain HTML content/items are
I need to verify input which is like en-US or en-us or ar-AE I
I need to verify if user have entered desired characters in the input field
I need to verify something for which I have doubts. If a shared library
I need to verify if an widget which basically is a .zip are according
In a bash script I need to verify that the user inputs actual numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.