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

  • Home
  • SEARCH
  • 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 7165759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:18:12+00:00 2026-05-28T14:18:12+00:00

I have an inline lambda expression that I would like to use throughout my

  • 0

I have an inline lambda expression that I would like to use throughout my application. I just can’t seem to find a reference on how to do this with more parameters than the element being tested. Here is a quick example of what I currently have.

Private Sub Test()
    Dim List As New List(Of String) From {"Joe", "Ken", "Bob", "John"}
    Dim Search As String = "*Jo*"
    Dim Result = List.Where(Function(Name) Name Like Search)
End Sub

I know the IEnumerable.Where accepts a method with the element type as a parameter and a returning boolean.

Private Sub Test()
    Dim List As New List(Of String) From {"Joe", "Ken", "Bob", "John"}
    Dim Search As String = "*Jo*"
    Dim Result = List.Where(AddressOf FindName)
End Sub

Private Function FindName(Name As String) As Boolean
    Return Name Like "*Jo*"
End Function

I would like to pass the Search variable into FindName as well. I just can’t seem to get the syntax figured accomplish this. The only working solution I’ve come up with is passing everything to a function to perform the original statement.

Private Sub Test()
    Dim List As New List(Of String) From {"Joe", "Ken", "Bob", "John"}
    Dim Search As String = "*Jo*"
    Dim Result = FindName(List, Search)
End Sub

Private Function FindName(List As IEnumerable(Of String), Search As String) As IEnumerable(Of String)
    Return List.Where(Function(Name) Name Like Search)
End Function

Don’t feel obligated to answer in VB.

  • 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-28T14:18:13+00:00Added an answer on May 28, 2026 at 2:18 pm

    The nice thing with lambda expressions is that they allow closures to automatically capture variables that are local to your scope. For example (pardon the C#):

    List.Where(i => FindName(i, Search));
    

    In the above code, the Search variable is actually being encapsulated in a closure. If you want to just pass a method, you’ll have to simulate what closures do with an actual class structure:

    public class NameFinder
    {
        private string _search;
        public NameFinder(string search) {
            _search = search;
        }
        public bool Match(string item) {
            // C# equivalent of "return item LIKE _search"
        }
    }
    
    // Usage
    var nameFinder = new NameFinder(Search);
    List.Where(nameFinder.Match);
    

    However, this strategy is only useful in a small subset of cases. I find it’s usually best to just use a lambda expression that passes the appropriate variables into the function that does all the work.

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

Sidebar

Related Questions

To have a general-purpose documentation system that can extract inline documentation of multiple languages,
I have a class that had an inline member, but I later decided that
If I use the inline function in MATLAB I can create a single function
I have Django application with inline in place: class Account(models.Model): ContractNum = models.PositiveIntegerField(unique=True, blank=True,
I have a member profiles application that stores simple information about members of a
Is it possible to create an inline delegate in vb.net like you can in
Background: we have an application that generates reports from HTML (that may or may
I would like to be able to manipulate the DOM just before my page
I have some inline code in an aspx file that executes: <dd><%= encode(Listing.Address.Line1) %>
Say I have several inline-block div tags, like this <div class=image> </div> <div class=image>

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.