【问题标题】:Searching one array then get the corresponding data from another array搜索一个数组,然后从另一个数组中获取相应的数据
【发布时间】:2015-03-31 01:52:09
【问题描述】:

如何从用户输入中搜索一个数组中的数据并从其他数组中获取相应的数据?例如,用户希望通过在另一个数组中搜索具有 id 编号的姓名来获取信息。

【问题讨论】:

    标签: c# arrays string search


    【解决方案1】:

    我在这种情况下使用 Linq。

     public class Person
     {
          public string Name { get; set; }
          public int Id { get; set; }
     }
    
    
     IEnumerable<string> names = data.Where(x => input.Any(y => y.Id == x.Id)).Select(x => x.Name);
    

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 2021-06-24
      • 2020-12-22
      • 1970-01-01
      • 2013-06-11
      • 2018-03-28
      • 2016-03-22
      • 2016-12-10
      • 1970-01-01
      相关资源
      最近更新 更多