CodeRonnie
CodeRonnie

Reputation: 39

What is this object instantiation syntax called? Object obj = new();

Microsoft documentation has a code example here that uses syntax for instantiating an object that I have not seen before. I searched the web for more information on this syntax as well as I could, but I could not seem to find additional information. The object is instantiated with the new keyword, but no class name. I assume the type is inferred from the variable it is being assigned to, but I would like to know more, specific information about this operation.

Does this instantiation syntax have a specific name? Does anyone have a link to some official documentation that explains which versions of the language support this feature, or any additional information?

 using StreamWriter file = new("WriteLines2.txt", append: true);

Upvotes: 1

Views: 55

Answers (1)

krontogiannis
krontogiannis

Reputation: 1939

It's called Target typed new expression (introduced in C# 9)

Upvotes: 2

Related Questions