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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:42:29+00:00 2026-05-13T07:42:29+00:00

struct SomeStruct { public int Num { get; set; } } class Program {

  • 0
struct SomeStruct
{
    public int Num { get; set; }
}

class Program
{
    static Action action;

    static void Foo()
    {
        SomeStruct someStruct = new SomeStruct { Num = 5 };
        action = () => Console.WriteLine(someStruct.Num);
    }

    static void Main()
    {
        Foo();
        action.Invoke();
    }
}
  1. Is a copy of someStruct created when the lambda is created?
  2. Is a copy of someStruct created when Foo returns?
  3. Can I verify that copying doesn’t occur? In C++ I’d implement the copy constructor and print from inside it.

Citations from the standard will be appreciated. Any relevant online articles as well.

  • 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-13T07:42:29+00:00Added an answer on May 13, 2026 at 7:42 am

    There will be no copies. Lambdas capture variables, not values.

    You can use Reflector to look at the compile code: the compiler will move the “someStruct” variable into a helper class.

    private static void Foo()
    {
        DisplayClass locals = new DisplayClass();
        locals.someStruct = new SomeStruct { Num = 5 };
        action = new Action(locals.b__1);
    }
    private sealed class DisplayClass
    {
        // Fields
        public SomeStruct someStruct;
    
        // Methods
        public void b__1()
        {
            Console.WriteLine(this.someStruct.Num);
        }
    }
    

    Copying structures will never cause user-defined code to run, so you cannot really check it that way.
    Actually, the code will do a copy when assigning to the “someStruct” variable. It would do that even for local variables without any lambdas.

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

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer http://www.rattlesnake.com/intro/Yanking.html#Yanking It's from Emacs. Basically it's a list of copied… May 13, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer Nobody has extensive experience with Unladen Swallow yet (except the… May 13, 2026 at 8:19 pm
  • Editorial Team
    Editorial Team added an answer According to the header file, the backgroundView defaults to nil… May 13, 2026 at 8:19 pm

Related Questions

I would like to do the following: [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SomeStruct
I am calling into a native dll from C#. For the specific function in
Given a struct like this: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty)
struct SomeStruct; typedef struct SomeStruct SomeStruct; The above works, but is there a simpler
struct SomeStruct { int a; int b; }; SomeStruct someFn( int init ) {

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.