Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple properties using Lambda in Action delegate

Tags:

c#

lambda

linq

This is probably simple, but I can't figure out how to set multiple properties in a single statement.

LCCorsOptions.cs:

public class LCCorsOptions
{
    public int AppId { get; set; }
    public string Version { get; set; } = "1.0";
}

This is what I got so far:

app.UseLCCors(o => o.Version = "1.0");

I've tried multiple approaches, but with no luck

like image 394
SteinTheRuler Avatar asked Apr 26 '26 03:04

SteinTheRuler


1 Answers

This is about lambda syntax, the part on the right is a normal method body that you may shorten when it is 1 expression or 1 statement. Otherwise, use full { }and ;

app.UseLCCors(o => {o.Version = "1.0"; o.AppId = 2; });
like image 158
bommelding Avatar answered Apr 27 '26 17:04

bommelding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!