What is the name of this C# syntax?
Asked Answered
B

1

5

In C#, you can do something like this:

SomeClass someClass = new SomeClass () {
    SomeProperty = someValue
};

What is this syntax called?

Boatsman answered 30/12, 2009 at 3:48 Comment(1)
BTW, you don't need the parentheses (), if they are not supplied the parameter-less constructor will be invoked by default.Terrific
S
18

Object initializer is the name.

Succinctorium answered 30/12, 2009 at 3:49 Comment(3)
Wouldn't that be more like "Object initializer the name is. Hmmph! Much to learn you have."Frasch
If so smart Yoda is, right order words in his sentences Yoda puts not why?Gerlachovka
If I remember my Star Wars mythos correctly, Yoda spoke grammatically correct english up until the day he read Chapter 7: Wisdom You Have Not, But Sound Like It You Will of the book Jedi Grammer Hacks: You May Have The Force, But Your Words Are Not Forceful. ...or I just made that up.Frasch

© 2022 - 2024 — McMap. All rights reserved.