Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Linq query on arrays of tuples

(Type, int)[] Format1 = new[] {(typeof(Foo),1)};

(Type, int)[] Format2 = new[] { (typeof(Bar), 1),(typeof(Baz),1) };

IEnumerable<Type> allTypes() => //Foo,Bar,Baz

Can you help with:

  1. how to temporarily union Format1 and Format2 in a quick way, so that…
  2. we can extract the types out of the tuples and return them in allTypes()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

IEnumerable<Type> allTypes() => Format1
    .Select(t => t.Item1)
    .Union(Format2.Select(t => t.Item1));

Union removes duplicates as desired, otherwise use Concat.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading