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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:54+00:00 2026-06-10T07:53:54+00:00

I have the following lambda expression: string queryToken = queryTokens.Last(); var result = from

  • 0

I have the following lambda expression:

string queryToken = queryTokens.Last();
var result = from locationAddress in locations
             let tokens = GetLetterTokens(locationAddress.Name)
             let distance = (from token in tokens
                             where token.Contains(queryToken, StringComparison.OrdinalIgnoreCase)
                             select token.Length - queryToken.Length).Min()
             orderby distance
             select new
                        {
                            LocationAddress = locationAddress,
                            LocationDistance = distance,
                        };

It doesn’t matter what it’s written for. Sometimes when counting distance, there are no tokens containing queryToken, so .Min() couldn’t be returned. How to skip these cases? I don’t want to add them into result variable.

  • 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-10T07:53:56+00:00Added an answer on June 10, 2026 at 7:53 am

    Sounds like you just want:

    let tokens = ...
    where tokens.Any(token.Contains(queryToken, StringComparison.OrdinalIgnoreCase))
    let distance = ...
    

    Alternatively, just filter when you select the tokens, and then check whether any exist:

    var result = from locationAddress in locations
                 let tokens = GetLetterTokens(locationAddress.Name)
                                  .Where(token => token.Contains(queryToken, StringComparison.OrdinalIgnoreCase)
                 where tokens.Any()
                 let distance = tokens.Min(token => token.Length - queryToken.Length)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda
I have simple lambda as a string: var str = f => f.Substring(0, f.IndexOf('
Supposing I have the following LambdaExpression: var itemParam = Expression.Parameter(typeof(Thing), thing); var someValue =
When trying to run the following code: Expression<Func<string, string>> stringExpression = Expression.Lambda<Func<string, string>>( Expression.Add(
Let's say you have the following code: string encoded=9,8,5,4,9; // Parse the encoded string
Possible Duplicate: How to pass a lambda expression in Elisp I have following code:
I have the following lambda function: f = lambda x: x == None and
I have a following simple code: def get(): return [lambda: i for i in
I have the following named scope: named_scope :report_search, lambda { |search| { :conditions =>
If I have the following named_scope named_scope :scope_by_user_id, lambda {|user_id| {:conditions => [comments.user_id =

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.