0

In namespace Microsoft.AspNetCore.Builder in the class WebApplication there is this strange syntax in line 98 or 106. What does this mean?

 public static WebApplicationBuilder CreateBuilder() =>
        new(new());


 public static WebApplicationBuilder CreateBuilder(string[] args) =>
        new(new() { Args = args });
Rand Random
  • 7,300
  • 10
  • 40
  • 88
Isaac Tack
  • 91
  • 1
  • 3
  • 3
    @CodeCaster It's not an anonymous object, but its type is inferred from context by the compiler. `new()` is not anonymouse, `new {}` is. – Zohar Peled May 17 '23 at 11:25
  • 2
    It is twice a "[target-typed new expression](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new)". It basically states `=> new WebApplicationBuilder(new WebApplicationOptions { Args = args }))`. See duplicate. – CodeCaster May 17 '23 at 11:28
  • 1
    @Zohar I don't know how I missed the `()` twice, thanks. – CodeCaster May 17 '23 at 11:28

0 Answers0