Is there any difference between the { e.MapControllers(); } and the e.MapControllers() ?

@Middleware & OS Hi everyone in C#, when using lambda expressions with the UseEndpoints method, what's the difference between including curly braces and omitting them? From my code example :
public void Configure(IApplicationBuilder app)
{
... //my other codes
app.UseEndpoints(e => e.MapControllers());

app.UseEndpoints(e => { e.MapControllers(); });
}
public void Configure(IApplicationBuilder app)
{
... //my other codes
app.UseEndpoints(e => e.MapControllers());

app.UseEndpoints(e => { e.MapControllers(); });
}
Is there any difference between the { e.MapControllers(); } and the e.MapControllers() ? And why would the MapControllers be called twice in this case?
4 Replies
Enthernet Code
Enthernet Code6mo ago
@Marvee Amasi Including curly braces signifies a block of code while without curly braces signifies a single statement
Enthernet Code
Enthernet Code6mo ago
And I also think there's an error in your code as you stimulated both instances of braces and without braces, because if you call the e.mapcontrollers() it would call the function which is duplicate in your code
Marvee Amasi
Marvee Amasi6mo ago
@Enthernet Code Oh yh Calling e.MapControllers() twice would indeed be redundant. In my example, I accidentally included it when invoking both UseEndpoints.
public void Configure(IApplicationBuilder app)
{
... //my other codes
app.UseEndpoints(e=>
{
e.MapControllers();
});
}
public void Configure(IApplicationBuilder app)
{
... //my other codes
app.UseEndpoints(e=>
{
e.MapControllers();
});
}
Marvee Amasi
Marvee Amasi6mo ago
Thanks 👍
Want results from more Discord servers?
Add your server