What’s this C#resource called

Asked

Viewed 32 times

1

I always saw it in the c#

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

Only now I saw that the way below also the, accessing the properties directly with {, what this resource is called?

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

1 answer

1


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

Note that this is not the same as a constructor. This code is executed afterward of the construction of the object Button, of his example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.