What this feature calls C # [duplicate]

1

I always saw this in C #

var button = new Button(this.ApplicationContext);
button.Text = "New button;

But now I have seen that the form below also gives, accessing the properties directly with { , what is this feature called?

var button = new Button(this.ApplicationContext)
 {
      Text = "New button"
 };
    
asked by anonymous 28.05.2017 / 08:00

1 answer

1

This is a object . In practice, what C # does is transform the second form into the first one when compiling your code.

See that this is not the same as a builder. This code executes after of the construction of the object Button , of its example.

    
28.05.2017 / 08:10