ITADN

[Proposal]: Compound assignment in object initializer and `with` expression

#9896Openjnm2 创建于 2025-12-19
Proposal champion
J
jnm2commented
# Compound assignment in object initializer and `with` expression - Specification: https://github.com/dotnet/csharplang/blob/main/proposals/compound-assignment-in-initializer-and-with.md - Discussion: https://github.com/dotnet/csharplang/discussions/8650 ## Summary Allow compound assignments in an object initializer: ```cs var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1d), Tick += (_, _) => { /*actual work*/ }, }; ``` Or a `with` expression: ```cs var newCounter = counter with { Value -= 1 }; ``` ## Design meetings https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-09-20.md#object-initializer-event-hookup
0 条评论