-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02Deconstruction.cs
32 lines (26 loc) · 968 Bytes
/
02Deconstruction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
namespace CSharp7Console
{
public class Deconstruction
{
//Shortened named fields in the tuple
private static (int age, string department) GetEmployeeByIdNamedFields(int employeeId)
{
var empAge = 32;
var dept = "HR";
return (empAge, dept);
}
public static void DeconstructionExample()
{
//deconstruct immediately and remove the need to hold onto the tuple.
(int age, string dept) = GetEmployeeByIdNamedFields(1);
Console.WriteLine($"{age} {dept}");
//or with var
(var employeeAge, var employeeDept) = GetEmployeeByIdNamedFields(1);
Console.WriteLine($"{employeeAge} {employeeDept}");
//Even lazier var...
var (employeeAge2, employeeDept2) = GetEmployeeByIdNamedFields(1);
Console.WriteLine($"{employeeAge2} {employeeDept2}");
}
}
}