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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:53:27+00:00 2026-05-16T03:53:27+00:00

Given this code: int min = 0; Expression<Func<List<IUser>, bool>> ulContainsJohn = (l => l.Where(u

  • 0

Given this code:

        int min = 0;

        Expression<Func<List<IUser>, bool>> ulContainsJohn = 
                    (l => l.Where(u => u.FirstName == "John").Count() > min);

        Assert.AreEqual(true, ulContainsJohn.Compile()(userList));

        min = 3;

        Assert.AreEqual(true, ulContainsJohn.Compile()(userList));

The list contains 1 “John”, yet the second assert fails. How do I bind the value of min to the Func eagerly, so it doesn’t try to re-evaluate the variable min?

Clarification: I don’t want to change the signature. I want the expression tree to avaluate min not as a variable, but as a constant expression. Is there anyway to convert the evaluation of min so that the tree has a constant expression instead of a variable evaluation?

  • 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-16T03:53:29+00:00Added an answer on May 16, 2026 at 3:53 am

    Edit: read your comment, try a function creator.

    Func<int, Func<List<IUser>, bool>> createFn = (min) =>
        (l) => (l.Count(u => u.FirstName == "John") > min);
    
    Func<List<IUser>, bool>> contains0 = createFn(0);
    
    Assert.AreEqual(true, contains0(userList));
    
    Func<List<IUser>, bool>> contains3 = createFn(3);
    
    Assert.AreEqual(true, contains3(userList));
    

    Try using a 1 element array. Ugly, but it works.

    var values = new int[] { 0 };
    
    Expression<Func<List<IUser>, bool>> ulContainsJohn = 
                    (l => l.Where(u => u.FirstName == "John").Count() > values[0]);
    
    Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
    
    values[0] = 3;
    
    Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
    

    Another option, better:

    private int Minimum { get; set; }
    
    ...
    
    Expression<Func<List<IUser>, bool>> ulContainsJohn = 
                (l => l.Where(u => u.FirstName == "John").Count() > Minimum);
    
    Func<List<IUser>, bool> fn = ulContainsJohn.Compile();
    Assert.AreEqual(true, fn(userList));
    
    Minimum = 3;
    
    Assert.AreEqual(true, fn(userList));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
Why does this code int (*g)(int); int (*h)(char); h = g; In C, give
Given this code, tableButton = new JButton(new ImageIcon(80F_FG2015.GIF)); how would I get that String
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
So I was given this code in a folder of bits and pieces that
I'm learning about pointers. Given this code: FILE* from = fopen("in.txt", "r"); FILE* to
Given this JavaScript code (which is just a comment referring to a url): //
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
I was given this Python code that would calculate an MD5 value for any

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.