C#7 value tuples and deconstruction

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		(string a, string b) = F();

		(string a, string b) ab = F();
		
		Console.WriteLine($"a: {a} b: {b} ab: {ab}");
		

		var c = new C();
		
		(string d, string e) = c;

		(string a, string b) f = c;
		
		Console.WriteLine($"d: {d} e: {e} f: {f}");

		//  Covariance
		(object c, object d) g = F();
		//  Implicit conversion
		(double x, double y) t = G();
	}
	
	public static (string a, string b) F() 
		=> ("A", "B");

	public static (int x, int y) G() 
		=> (0, 1);
}


public class C
{
	public String A = "A";
	public String B = "B";
	
	public void Deconstruct(out String a, out String b)
	{
		a = A;
		b = B;
	}
}

;