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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:09:45+00:00 2026-06-11T08:09:45+00:00

I need to get the count of items specified in a string[] which satisfies

  • 0

I need to get the count of items specified in a string[] which satisfies my condition. So, I tried Predicate and defined my condition using the same. But my code is not working. Can anyone please help me?

string[] books = new string[] { "Java", "SQL", "OOPS Concepts", "DotNet Basics"};

Predicate<string> longBooks = delegate(string book) { return book.Length > 5; };
int numberOfBooksWithLongNames = books.Count(longBooks);

When I run this, it shows a compile time error. Please see below:

‘string[]’ does not contain a definition for ‘Count’ and the best extension method overload ‘System.Linq.Enumerable.Count(System.Collections.Generic.IEnumerable, System.Func)’ has some invalid arguments

  • 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-06-11T08:09:47+00:00Added an answer on June 11, 2026 at 8:09 am

    The LINQ Count() method does not take a Predicate as a parameter. In your case the method takes a delegate of type Func<string, bool>. So there are a couple ways you can fix your code, the simplest would probably be to do what others have suggested and use a lambda. Or, using your original code just change Predicate<string> to Func<string, bool>:

    string[] books = new string[] { "Java", "SQL", "OOPS Concepts", "DotNet Basics"};
    
    Func<string, bool> longBooks = delegate(string book) { return book.Length > 5; };
    int numberOfBooksWithLongNames = books.Count(longBooks);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the number of items that have a comment but I
I'm using Json.net for a project and I need to get specific items (in
I've 3 collections with exactly the same items count. I need to create a
In SQL SERVER 2008 R2, I need to get a count of items contained
I need to get a get a count of all the distinct subnets in
I need to get the subscriber count/list of a Youtube user, is there any
I'm working on a project where I need to get the total row count
I need something to get the hard link count from a file in a
So i need to figure out how i can get a record count value
I need get the id of an images which is place inside a datatemplate..

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.