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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:05:09+00:00 2026-05-30T11:05:09+00:00

I have this expression : Expression<Func<string, bool>> f = s => s.Length < 5;

  • 0

I have this expression :

Expression<Func<string, bool>> f = s => s.Length < 5;

enter image description here

ParameterExpression p = Expression.Parameter (typeof (string), "s");
MemberExpression stringLength = Expression.Property (p, "Length");
ConstantExpression five = Expression.Constant (5);
BinaryExpression comparison = Expression.LessThan (stringLength, five);
Expression<Func<string, bool>> lambda= Expression.Lambda<Func<string, bool>> (comparison, p);

//lets : test

Func<string, bool> runnable = lambda.Compile();
Console.WriteLine (runnable ("kangaroo")); // False
Console.WriteLine (runnable ("dog")); //True

I want to ask about the .Compile()

What does it compile ? And what is the difference between the first execution vs later executions…?

Compile should be something that happens once and not happens again later ….

What / How does it help me ?

  • 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-30T11:05:11+00:00Added an answer on May 30, 2026 at 11:05 am

    When you are building the expression tree at runtime there’s no code emitted. It’s a way to represent .NET code at runtime.

    Once you call the .Compile method on the expression tree the actual IL code is emitted to convert this expression tree into a delegate (Func<string, bool> in your case) that you could invoke at runtime. So the code that this expression tree represents can be executed only after you compile it.

    Calling Compile is an expensive operation. Basically you should be calling it once and then caching the resulting delegate that you could use to invoke the code many times.

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

Sidebar

Related Questions

I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o =>
I have this code: string name =M; Expression<Func<Organization, bool>> getExpression1 = r => r.Name.Contains(name);
I have this generic method in my repository: public T GetFirstOrDefault(Expression<Func<T, bool>> where, Expression<Func<T,
I have the following code. public void GetMessages(Expression<Func<IMessageQueryable, bool>> messageSpecification, string folder = INBOX)
Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I thought this was fixed in 4.0. I have this method public IQueryable<T> All(Expression<Func<T,object>>
Possible Duplicate: combining two lamba expressions in c# I have two following expressions: Expression<Func<string,
public static bool Compare<T>(this T source, T other, params Expression<Func<T>>[] propertiesToSkip) { PropertyInfo[] sourceProperties
I have extension method: public static IQueryable<TResult> WithFieldLike<TResult>( this IQueryable<TResult> query, Func<TResult, string> field,

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.