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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:15:52+00:00 2026-05-11T03:15:52+00:00

Does the order in which I set properties using the object initializer syntax get

  • 0

Does the order in which I set properties using the object initializer syntax get executed in the exact same order?

For instance if I do this:

var s = new Person { FirstName = 'Micah',                      LastName = 'Martin',                      IsLoaded = true                    } 

will each property get set in the same order?

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

    Yes.

    Apologies for getting interrupted (I have to actually do some work every so often). The spec doesn’t explicitly say it, but it makes it pretty clear IMO in section 7.6.10.2:


    An object initializer consists of a sequence of member initializers, enclosed by { and } tokens and separated by commas.

    (Note the word "sequence" here, rather than "set". I personally think that’s significant, as a sequence is ordered.)

    The following class represents a point with two coordinates:

    public class Point {     int x, y;     public int X { get { return x; } set { x = value; } }     public int Y { get { return y; } set { y = value; } } } 

    An instance of Point can be created and initialized as follows:

    Point a = new Point { X = 0, Y = 1 }; 

    which has the same effect as

    Point __a = new Point(); __a.X = 0; __a.Y = 1;  Point a = __a; 

    where __a is an otherwise invisible and inaccessible temporary variable.


    EDIT: I’ve had a response from Mads Torgersen, who has basically said that anything which can be done now will preserve the order. There may be some oddities in future where the order is not preserved in weird cases where you’re doing something other than setting a property/field, but that will depend on where the language goes.

    It’s worth pointing out that there are actually lots of steps going on here – there’s the order of execution of the evaluation of the arguments (i.e. the RHS bits) and the order of execution of the assignments. For example, if you have:

    new Foo {     A = X,     B = Y } 

    all the following orders are possible while still maintaining the order of the actual property execution (A and B):

    • Evaluate X, assign to A, evaluate Y, assign to B
    • Evaluate X, evaluate Y, assign to A, assign to B
    • Evaluate Y, evaluate X, assign to A, assign to B

    I believe the first option is the one actually taken, but this was just to demonstrate that there’s more to it than meets the eye.

    I would also be very wary of actually writing code which depends on this…

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use x64 Standard, Enterprise, or Data Center. This… May 11, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer You can use a foreach statement to get the key… May 11, 2026 at 4:55 pm
  • Editorial Team
    Editorial Team added an answer Definitely. Query syntax is just a syntactic sugar. It'll be… May 11, 2026 at 4:55 pm

Related Questions

I am working with a Visual Studio 2005 C++ solution that includes multiple projects
I'm planning a WPF application which will be able to create dynamic data entry
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a code file from the boto framework pasted below, all of the

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.