Reputation: 721
Recently I ran into this code but I don't know the terminology so I couldn't search on Google to learn more about this coding style.
Here's the code:
SomeObject someObject = new SomeObject()
{
Name = "name",
Value = 10
};
Does anyone know what is this called in C#?
Upvotes: 0
Views: 53
Reputation: 79631
It's called initializer syntax and it is essentially doing the same thing as the following, but in a single expression:
SomeObject someObject = new SomeObject();
someObject.Name = "name";
someObject.Value = 10;
Upvotes: 3
Reputation: 39827
I believe what you are looking for is called an Object Initializer
From the MSDN:
You can use object initializers to initialize type objects in a declarative manner without explicitly invoking a constructor for the type.
Upvotes: 0
Reputation: 9018
This is called Object initializer . See documentation for Object initializers
Upvotes: 1