Skip to content

Latest commit

 

History

History
44 lines (27 loc) · 1.67 KB

expression-variables-in-initializers.md

File metadata and controls

44 lines (27 loc) · 1.67 KB

expression variables in initializers

  • Proposed
  • Prototype: None
  • Implementation: None
  • Specification: See below

Summary

We extend the features introduced in C# 7 to permit expressions containing expression variables (out variable declarations and declaration patterns) in field initializers, property initializers, ctor-initializers, and query clauses.

Motivation

This completes a couple of the rough edges left in the C# language due to lack of time.

Detailed design

We remove the restriction preventing the declaration of expression variables (out variable declarations and declaration patterns) in a ctor-initializer. Such a declared variable is in scope throughout the body of the constructor.

We remove the restriction preventing the declaration of expression variables (out variable declarations and declaration patterns) in a field or property initializer. Such a declared variable is in scope throughout the initializing expression.

We remove the restriction preventing the declaration of expression variables (out variable declarations and declaration patterns) in a query expression clause that is translated into the body of a lambda. Such a declared variable is in scope throughout that expression of the query clause.

Drawbacks

None.

Alternatives

The appropriate scope for expression variables declared in these contexts is not obvious, and deserves further LDM discussion.

Unresolved questions

  • What is the appropriate scope for these variables?

Design meetings

None.