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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:25:03+00:00 2026-05-25T06:25:03+00:00

Is there any way one can apply a function with signature bool IsOdd(int number);

  • 0

Is there any way one can apply a function with signature

bool IsOdd(int number);

to an array of integers and return whether any given integer in that array is odd in a single instruction? I know I can use

return (array.Where(IsOdd).Count() > 0);

but that implies calling two methods and making a comparison… Isn’t there really a shorter way to achieve the same?

  • 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-25T06:25:03+00:00Added an answer on May 25, 2026 at 6:25 am

    Yes.

    To start with you could use the form of Count which takes a predicate:

    return array.Count(IsOdd) > 0;
    

    … but you don’t want to do that. That code is still expressing a numerical comparison which is unnecessary. You want to ask if any item in the array is odd. In other words:

    return array.Any(IsOdd);
    

    Not only is this more expressive – it’s also potentially much faster. As soon as Any finds a match, it will return true – whereas Count would have to iterate over the whole array to find out exactly how many matches there are.

    Basically, whenever you see a LINQ query using Count() > 0 you should think about using Any instead. In some cases with expression-tree-based queries such as LINQ to SQL it may not make a performance difference (if the query optimizer has visibility of the comparison with 0) but in LINQ to Objects it certainly can.

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

Sidebar

Related Questions

Is there any way I can combine list of expressions into one? I have
Is there any way to run one same instance of JavaCcript(jQuery) on the server
Is there any way to have this: [one[two]][three] And extract this with a regex?
Is there any way to change Firefox system icon (the one on the left
Is there any way to modify the bound value of one of the variables
Is there any way to add reference from one winforms to another winforms?? There
Is there any way to modify the CSS properties of one table's cells based
Is there any way to connect more then one PPC to ActiveSync in one
Is there any way to git pull all folders in the repository but one?
This one is pretty out there, but I can't find any posts addressing it

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.