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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:40:11+00:00 2026-05-15T16:40:11+00:00

How could I construct a LINQ expression to remove values from one list that

  • 0

How could I construct a LINQ expression to remove values from one list that meet the criteria of a function that returns a boolean?

string[] message = "days of the week"
message.ToList().RemoveAll(c=>checkShortWord(c));

public static bool checkShortWord(string word) {
       if ((word.Length > 3) &&                        
          (!Regex.IsMatch(word, "^[0-9]+$")))          
        return true;

      return false;
}

My ending string array should now be:

message = {"days","week"}

What should I change? My message array never changes.

  • 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-15T16:40:11+00:00Added an answer on May 15, 2026 at 4:40 pm

    You are constructing a new List and removing the items from that list, and then throwing it away. If you want an array that is missing the removed items, you will need to create a new one:

    string[] message = "days of the week".Split(' ');
    message = message.Where(c => checkShortWord(c)).ToArray();
    

    Alternately, you could use a List<String> instead of a string[], and then use the RemoveAll method to modify it in place:

    List<string> message = "days of the week".Split(' ').ToList();
    message.RemoveAll(c => !checkShortWord(c));
    

    As others have mentioned, you have also named your predicate method badly. “IsLongWord” might be more appropriate. You could write it a little more simply like this:

    public static bool IsLongWord(string word)
    {
        return word.Length > 3 && !Regex.IsMatch(word, "^[0-9]+$");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to construct my linq-to-sql expression so that it only generates a single
I have a Linq provider that sucessfully goes and gets data from my chosen
I know 2 ways to remove doubles from an array of objects that support
What I'd like to be able to do is construct a LINQ query that
If I wanted to badly enough, could I add additional LINQ constructs to LINQ-to-SQL
I was debating with a friend who states that the static constructor could give
Could someone know where is saved path to external XML-File that contain configuration for
I need a bit of inspiration from somewhere and hoping someone, anyone could help.
I've got 2 LINQ-to-SQL lists and I merge them into 1 list using: var
LinQ contains the method Cast which casts each entry in the list to type

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.