C# 7 tuples and lambdas

前端 未结 4 1232
[愿得一人]
[愿得一人] 2020-12-15 02:36

With new c# 7 tuple syntax, is it possible to specify a lambda with a tuple as parameter and use unpacked values inside the lambda?

Example:

var list         


        
4条回答
  •  庸人自扰
    2020-12-15 03:00

    Deconstructions in C# 7.0 support three forms:

    • deconstruction-declaration (like (var x, var y) = e;),
    • deconstruction-assignment (like (x, y) = e;),
    • and deconstruction-foreach (like foreach(var(x, y) in e) ...).

    Other contexts were considered, but likely have decreasing utility and we couldn't complete them in the C# 7.0 timeframe. Deconstruction in a let clause (let (x, y) = e ...) and in lambdas seem good candidates for future expansion.

    The latter is being discussed in https://github.com/dotnet/csharplang/issues/258

    Do voice your feedback and interest there, as it will help champion proposals.

    More details on what was included in C# 7.0 deconstruction in the design doc.

提交回复
热议问题