I have found this syntax in MS docs:
public NewsStoryViewModel(DateTimeOffset published, string title, string uri) =>
(Published, Title, Uri) = (published, title, uri);
It does multiple assignment in one statement, but I am not quite sure what it's called or how it works.
Is this some kind of a trick do multiple assignment by pretending these are tuples or does it have it's own name?
P.S. It is mentioned here if anyone is interested
P.P.S. It's not the absence of {} I am wondering about, but rather line 2 with a "fancy" assignment instead of a traditional one.
It's a tuple that is deconstructed to class properties.
public NewsStoryViewModel(DateTimeOffset published, string title, string uri) {
// tuple
var myTuple = (published, title, uri);
// deconstruction
(Published, Title, Uri) = myTuple;
}
Deconstruction works for tuples out of the box. See https://learn.microsoft.com/en-us/dotnet/csharp/tuples#deconstruction for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With