dotnet / dotnet/csharplang

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

Open
#9,896 0 comments 0 reactions 2 assignees Claimed by @CyrusNajmabadi View on GitHub
Proposal champion
Dominant language
C#
Stars
12.7k
Forks
1.1k
Avg merge
11h 1m
Merged PRs (30d)
3

Description

# 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.