【问题标题】:Linq query on arrays of tuples元组数组上的 Linq 查询
【发布时间】:2022-02-02 21:06:42
【问题描述】:
(Type, int)[] Format1 = new[] {(typeof(Foo),1)};

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

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

你能帮忙吗:

  1. 如何快速临时合并Format1Format2,以便...
  2. 我们可以从元组中提取类型并将它们返回到allTypes()

【问题讨论】:

标签: c# linq tuples


【解决方案1】:
IEnumerable<Type> allTypes() => Format1
    .Select(t => t.Item1)
    .Union(Format2.Select(t => t.Item1));

Union 根据需要删除重复项,否则使用Concat

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    相关资源
    最近更新 更多