Assigning events in object initializer

This didn’t make C# 6 or C# 7 (since the original question), however it hasn’t been decided against. There is an issue on GitHub that tracks the language proposal. You can vote for it there, as well as follow links into previous discussion around the feature.

https://github.com/dotnet/csharplang/issues/307

If you’d like to see this feature, add a thumbs-up to the issue to help raise its visibility.

The proposed syntax is:

var timer = new DispatcherTimer {
    Tick += delegate {},
    Interval = TimeSpan.FromSeconds(1d),
};

Leave a Comment