Is there a way to allow a list of tuples to deconstruct to a List<T>
?
I get the following compile error with the following code sample:
Cannot implicitly convert type 'System.Collections.Generic.List< Deconstruct.Test>' to 'System.Collections.Generic.List<(int, int)>'
using System;
using System.Collections.Generic;
namespace Deconstruct
{
class Test
{
public int A { get; set; } = 0;
public int B { get; set; } = 0;
public void Deconstruct(out int a, out int b)
{
a = this.A;
b = this.B;
}
}
class Program
{
static void Main(string[] args)
{
var test = new Test();
var (a, b) = test;
var testList = new List<Test>();
var tupleList = new List<(int, int)>();
tupleList = testList; // ERROR HERE....
}
}
}
tupleList = testList
? A new independent list containing copies of the original list's elements, converted to tuples? Or a wrapper list reflecting the contents of the original list, projected as tuples? – TurretList<T>
into a method which accepted a list of tuples as an argument. – PostpaidList<T>
or not. I guess that it doesn't, in which case @EliahuAaron's solution is completely sufficient. – Turret