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

  • Home
  • SEARCH
  • 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 950123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:30:59+00:00 2026-05-15T23:30:59+00:00

What is the fastest way to implement something like this in C#: private List<string>

  • 0

What is the fastest way to implement something like this in C#:

  private List<string> _myMatches = new List<string>(){"one","two","three"};
  private bool Exists(string foo) {
      return _myMatches.Contains(foo);
  }

note, this is just a example. i just need to perform low level filtering on some values that originate as strings. I could intern them, but still need to support comparison of one or more strings. Meaning, either string to string comparison (1 filter), or if string exists in string list (multiple filters).

  • 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-15T23:30:59+00:00Added an answer on May 15, 2026 at 11:30 pm

    You could make this faster by using a HashSet<T>, especially if you’re going to be adding a lot more elements:

    private HashSet<string> _myMatches = new HashSet<string>() { "one", "two", "three" };
    
    private bool Exists(string foo)
    {
        return _myMatches.Contains(foo);
    }
    

    This will beat out a List<T> since HashSet<T>.Contains is an O(1) operation.

    List<T>‘s Contains method, on the other hand, is O(N). It will search the entire list (until a match is found) on each call. This will get slower as more elements are added.

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

Sidebar

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.