.net - Order of operations using Object Initializer Syntax -


Do I set the property that is executed in the same sequence using the initial syntax? For example, if I do this:

  var s = new person {first name = "mica", last name = "martin", isled = true}  

/ Code>

Will each asset be set in the same order?

Yes.

Apologize for being interrupted (I actually have to do some work every time) This is not the fantasy clearly , but it makes very clear IMO in section 7.6.10.2 There is a sequence of member initials in the object analyzer,

(instead of the "set", here the "sequence" Note the word. I personally think that this is important because a sequence has been ordered.)

The following class represents a point with two coordinates:

  public square point {int x, y; Public int x {get {return x; } Set {x = value; }} Public int y {get {return y; } Set {y = value; }}  

An example of the point can be made and it can be started as follows:

  point = new point {X = 0 , Y = 1};  

has the same effect

  point __a = new point (); __a.x = 0; __a.Y = 1; Point A = __a;  

Where ___ is an otherwise invisible and unavailable temporary variable.


EDIT: I had a reaction from Mads Torgerson, who originally said that anything that can be done now will keep the order. There may be some inconvenience in the future, where the order is not kept safe in strange cases, where you are doing something other from the establishment of property / region, but it will depend on the language where language is is.

It is worth pointing out that there are really many steps here - the evaluation of the arguments (i.e., RHS bits) and the execution order order are executed. For example, if you have:

  new fu {A = X, B = y}  

all orders are possible after continuing with all orders Real Property Execution (A and B):

  • Evaluate X, Assign A, Evaluate Y, Assign to B
  • Evaluate X Assess, assign to A
  • Evaluate Y, evaluate x, assign A to A, assign to B.

My mother Not that the first option is actually taken, but it's just more of it to meet the eye in order to display it.

I too must be careful with the writing code, which depends on it ...


Comments