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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:42:46+00:00 2026-06-15T22:42:46+00:00

i got few line of code where configure method is calling and passing just

  • 0

i got few line of code where configure method is calling and passing just the string value but ConfigureWith function expect delegate. can anyone help me to understand how ConfigureWith() method will work. thanks

MailTemplate
.ConfigureWith(mt => mt.MailBody = "hello world")
.ConfigureWith(mt => mt.MailFrom = "rdingwall@gmail.com")
.DoSomeOtherStuff()
.Build();

The implementation for this would be:

public class MailTemplate
{
// regular auto properties
public string MailFrom { get; set; }
public string MailBody { get; set; }

public MailTemplate ConfigureWith(Action<MailTemplate> func)
{
    func(this);
    return this;
}


}
  • 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-15T22:42:48+00:00Added an answer on June 15, 2026 at 10:42 pm

    I see that the example above is from an answer to a different question you asked earlier. I’m still not entirely sure what you’re trying to do, and as Ian Mercer suggested, it’s pretty pointless as written. But if you’re just trying to understand what it does, then let’s first get a working example:

    using System;
    
    namespace ScratchApp
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                var mailTemplate = BuildMailTemplate(
                    mt => mt.MailBody = "hello world", 
                    mt => mt.MailFrom = "rdingwall@gmail.com");
            }
    
            private static MailTemplate BuildMailTemplate(
                Action<MailTemplate> configAction1, 
                Action<MailTemplate> configAction2)
            {
                var mailTemplate = new MailTemplate();
                mailTemplate.ConfigureWith(configAction1)
                    .ConfigureWith(configAction2)
                    .DoSomeOtherStuff()
                    .Build();
                return mailTemplate;
            }
        }
    
        public class MailTemplate
        {
            public string MailFrom { get; set; }
            public string MailBody { get; set; }
    
            public MailTemplate DoSomeOtherStuff()
            {
                // Do something
                return this;
            }
    
            public MailTemplate Build()
            {
                // Build something
                return this;
            }
    
            public MailTemplate ConfigureWith(Action<MailTemplate> func)
            {
                func(this);
                return this;
            }
        }
    }
    

    This is as pointless as before, but it builds. What’s happening when you’re calling .ConfigureWith() is that instead of passing a normal value, you’re passing it a function. In the example above, I’m actually declaring the functions as parameters that get passed into the BuildMailTemplate() method, and which in turn get executed when the template is being built and configured. You can get a feel for how it works by stepping through the code, line-by-line (e.g., F11 in Visual Studio), and setting breakpoints in the lambda expressions themselves, and then looking at the call stack.

    If you’re confused about the syntax for lambdas – arrow syntax is indeed a bit complex when you’re first getting used to it – then feel free to check out the MSDN article on it, or just Google “c# lambdas” to your heart’s delight.

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

Sidebar

Related Questions

I have got a few tables which I am trying to join. I just
folks, i got an issue which really pain for me i got few line
I've got Code Contracts working fine from inside Visual Studio 2010, but I can't
I've got code that compiles well enough, but when I try to run it,
I want to demonstrate with a few line of code that in Java, that
I got a line of code in the project i'm trying to modify/add extension
I was just playing around with CSS positioning and I have got a few
i have form in drupal which uploads images and has got few checkboxes in
So I have googled whole day, got few answers how to do this, and
I got a few WCFs that are running on an intranet on IIS 7.

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.