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

The Archive Base Latest Questions

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

Several methods in our code base use a ‘MaybeObject’ that can be passed into

  • 0

Several methods in our code base use a ‘MaybeObject’ that can be passed into functions when a result might be known, or might rely on an external webservice call that has not yet been carried out. For example, the property below can either have a specified known value, or if not specified and called after the async call is complete it will return the result of the Async call.

private string _internalString;
public string stringProp
{ 
    get
    {
        if (!string.IsNullOrEmpty(_internalString))
            return _internalString;
        return resultOfAsyncCallFromSomewhereElse;
    }

    set { _internalString = value; }
}

Obviously, trying to reference the property before the async call is complete would cause a null reference exception so we also have a flag to check if the value is available.

The question is, in the code below would the creation of the lambda try and evaluate stringProp (which might not be populated yet), or would evaluation be deferred until the resulting Action is called (which would be after checking the async operation is complete)?

public Action ExampleMethod(MaybeObject maybe)
{
    return () => doSomethingWithString(maybe.stringProp);
}
  • 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-27T03:32:01+00:00Added an answer on May 27, 2026 at 3:32 am

    Evaluation will be deferred until the resulting Action is called.

    The code referenced by a delegate is only executed when the delegate itself is explicitly invoked, regardless of how the delegate itself was created.

    For example, these ways of passing the code to execute through the Action delegate are all equivalent, and the doSomethingWithString method won’t be executed until a call to Action() is made:

    Explicit method (.NET 1.1):

    private MaybeObject maybe;
    
    public Action ExampleMethod()
    {
        return new Action(DoSomethingWithMaybeObject);
    }
    
    private void DoSomethingWithMaybeObject()
    {
        doSomethingWithString(maybe.stringProp)
    }
    

    Anonymous method (.NET 2.0):

    public Action ExampleMethod(MaybeObject maybe)
    {
        return delegate() { doSomethingWithString(maybe.stringProp) };
    }
    

    Lambda (.NET 3.5):

    public Action ExampleMethod(MaybeObject maybe)
    {
        return () => doSomethingWithString(maybe.stringProp);
    }
    

    See also:

    • Delegates
    • Anonymous Methods
    • Lambda Expressions
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our code base there are a few very long methods (several pages worth
I have recently become aware that our code has several implementations of a version
I have stumbled into several methods of looping in JavaScript, what I like the
I have several methods that deal with DB and all of them start by
I have several methods that populate a SQLCommand objects parameter collection from an object
If there are several methods in the test class, I found that the order
What's better practice when defining several methods that return the same shape of data
I have a class that currently has several methods that take integer parameters. These
I looked at several related answers, and determined that I can programmatically clear the
Currently I know several methods of connecting to a GUI remotely, or running GUI

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.