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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:57+00:00 2026-06-01T20:24:57+00:00

How can I use a Lambda expression as parameter in this method and use

  • 0

How can I use a Lambda expression as parameter in this method and use it in the where clause?

Been reading about Func, dynamic and Expression trees but not sure how to do this.

Problem is that I don’t know the type T and don’t know what the caller want returned.
How can I do this in C# 4.0?
An example to get me started would be great – thanks.

Here is a strongly simplified example of what I want.

static public List<T> Match(string startfilelocation, ???)
{
    var filelist = Directory.GetFiles(startfilelocation, "*.*", SearchOption.AllDirectories);
    return filelist.Where(???);
}

Thank you.

  • 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-01T20:24:58+00:00Added an answer on June 1, 2026 at 8:24 pm

    Specify List<string> as the return type, use the Func<string, bool> type for the parameter, then the ToList method to turn the result into a list:

    static public List<string> Match(string startfilelocation, Func<string, bool> filter) {
      var filelist = Directory.GetFiles(startfilelocation, "*.*", SearchOption.AllDirectories);
      return filelist.Where(filter).ToList();
    }
    

    Example:

    List<string> files = Match(folder, s => s.Contains("candy"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can I create a dynamic lambda expression to pass to use in my
What are the different scenario in which we can use Lambda Expression. One of
I have the following method I can pass in a lambda expression to filter
Can I use lambda expression to count the elements that I'm interested? For example,
Can you use a lambda expressions as an argument to an attribute? The motivation
You can use a standard dot notation or a method call in Objective-C to
You can use App.config; but it only supports key/value pairs. You can use .Net
I have an inline lambda expression that I would like to use throughout my
This is the code I need to alter: var xParam = Expression.Parameter(typeof(E), typeof(E).Name); MemberExpression
When I use Expression.Lambda( ... ).Compile() in order to create a delegate from an

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.