[Proposal] Allow assignment operators in with
expression
#8384
-
Allow assignment operators in public record Record(int Count, int IntValue, string? StringValue);
var myRecord = new Record(0, 100, "abc");
{
// as-is
var modified = myRecord with { Count = myRecord.Count + 1, IntValue = myRecord.IntValue - 1 };
}
{
// to-be
var modified = myRecord with { Count += 1, IntValue -= 1 };
var modified = myRecord with { Count++, IntValue-- };
}
{
// as-is
var modified = myRecord with { StringValue = myRecord.StringValue is not null ? myRecord.StringValue : "XYZ" };
}
{
// to-be
var modified = myRecord with { StringValue ??= "XYZ" };
} |
Beta Was this translation helpful? Give feedback.
Answered by
timcassell
Aug 23, 2024
Replies: 1 comment 1 reply
Answer selected by
acple
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#5176