语法LINQ的IEnumerable<字符串> [英] syntax in LINQ IEnumerable<string>

查看:127
本文介绍了语法LINQ的IEnumerable<字符串>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code,它的伟大工程:

  I prepository代表=新的I prepository();
  变种Q = rep.GetIp()
        。凡(X => x.CITY == CITY)
        .GroupBy(Y => o.Fam)
        。选择(Z =>新建IpDTO
        {
          IID = z.Key.Id,
          IP = z.Select(X => x.IP).Distinct()
       });
 

IP是的IEnumerable<字符串>

  1. 我需要添加到这个code调用一个函数 PAINTIP(IP)以上。
  2. 我需要发送,这将是内部IP给一个函数 PAINTIP(IP)元素中的每一个。 因此,我需要使用某种形式的foreach功能,但我无法弄清楚如何。
解决方案

  rep.GetIp()
   。凡(X => x.CITY == CITY)
   .GroupBy(Y => o.Fam)
   。选择(Z =>新建IpDTO
                    {
                        IID = z.Key.Id,
                        IP = z.Select(X => x.IP).Distinct()
                    })
   .SelectMany(项目=> item.IP)
   .ToList()
   .ForEach(PAINTIP)
 

This is my code that works great:

  IPRepository rep = new IPRepository();
  var Q = rep.GetIp()
        .Where(x => x.CITY == CITY)
        .GroupBy(y => o.Fam)
        .Select(z => new IpDTO
        {
          IId = z.Key.Id,
          IP = z.Select(x => x.IP).Distinct()
       });

IP is IEnumerable<string>

  1. I need to add to this code above a call to a function PAINTIP(ip).
  2. I need to send each one of the elements that will be inside IP to a function PAINTIP(ip). therefore i need to use some kind of foreach function but i cannot figure out how.

解决方案

rep.GetIp()
   .Where(x => x.CITY == CITY)
   .GroupBy(y => o.Fam)
   .Select(z => new IpDTO
                    {
                        IId = z.Key.Id,
                        IP = z.Select(x => x.IP).Distinct()
                    })
   .SelectMany(item => item.IP)
   .ToList()
   .ForEach(PAINTIP)

这篇关于语法LINQ的IEnumerable&LT;字符串&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆