Home > Enterprise >  Linq query on arrays of tuples
Linq query on arrays of tuples

Time:02-03

(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()

CodePudding user response:

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

Union removes duplicates as desired, otherwise use Concat.

  •  Tags:  
  • Related