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 7067157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:10:03+00:00 2026-05-28T05:10:03+00:00

I remember seeing a question on here about the same problem, where things like:

  • 0

I remember seeing a question on here about the same problem, where things like:

if( x==null || x==" " || x==" " || x=="\n")...

End up becoming long and ugly strings, but the answer wasn’t great and I can’t remember what it was.

I’m in the middle of a tutorial on MySQL, and the way the problem is solved in SQL is by using the keyword “IN”.

WHERE value IN (1 , 22, 35)...

So I was wondering if it’s considered inefficient or bad practice to do:

object[] BadVals = {null, " ", "  ", "\n"};
if(Array.IndexOf(BadVals, x) != -1)...
  • 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-28T05:10:03+00:00Added an answer on May 28, 2026 at 5:10 am

    It’s certainly not efficient in theory as the straight if test, but this is a red herring. The real question is: do you care?

    There’s two sides to this question.

    1. So what if it’s slower? If you aren’t running this on a CPU-bound loop that executes a million times, the difference is purely theoretical. Use whatever makes for more bug-free code that’s a pleasure to read and maintain.
    2. So what if it’s uglier? Are you going to be writing this lots of times? Surely not — if you intend to use it lots of times, put it inside a well-named method and never think about it again.

    As for the LINQ approach, that’s slightly shorter and a bit more readable than what you have:

    if((new[] { null, " ", "  ", "\n" }).Contains(x)) ...
    

    You ‘d probably want to write another extension method that allows you to call this with the operand positions reversed, e.g.

    if(x.In(new[] { null, " ", "  ", "\n" })) ...
    

    Verdict: I ‘d go with LINQ for more than 3 or so values to test against, provided that there’s no other more obvious way to check for these values (e.g. in this case IsNullOrWhiteSpace is awfully close) and there are no obvious performance implications. Otherwise, if is tried and true.

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

Sidebar

Related Questions

I remember seeing a question on my official MS 70-536 exam that talked about
I remember seeing a link about it here where some people claimed it's 1000
Sorry for this not being a real question, but Sometime back i remember seeing
I remember seeing a debate about this somewhere, and am currently considering removing a
I remember seeing online a (sql?) query designer tool that looked like the point
I'm looking for a good character that means end-of-story in unicode. I remember seeing
I remember seeing a blog post about how to fix the Visual Studio 2010
It seems like I remember seeing a web framework specifically for the Coming Soon
I remember seeing the code for a Highpass filter a few days back somewhere
I remember seeing in a sample a while ago that it is possible to

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.