Skip to content

[Proposal]: Deconstruction in from and let #8875

@MadsTorgersen

Description

@MadsTorgersen

Deconstruction in from and let

Summary

We only were able to implement P0 deconstruction scenarios in C# 7, which leaves a number of candidates unaddressed (let clause, from clause, lambda, method declaration, using, outvar, join clause, query continuation clause, join into clause, catch).

The first three in particular could use further investigation.

From clause

Instead of:

(int, int)[] tuples = new[] { (1, 2), (3, 4) };
var query = from t in tuples
        select t.Item1;

Allow:

var query = from (x, y) in tuples
        select x;

Let clause

var query = from deconstructable in deconstructables
        let (x, y) = deconstructable
        ...;

Lambda

Instead of:

tuples.Select(t => t.Item1 + t.Item2);

Allow:

tuples.Select((var (x, y)) => x + y); 
// the lambda takes one argument that is not named 
// and can be broken into two parts

Or maybe this syntax instead:

tuples.Select(((x, y)) => x +y); // same number of parentheses, but denser

Design meetings

https://github.com/dotnet/csharplang/blob/main/meetings/2016/LDM-2016-12-07-14.md#deconstruction

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions