zoukankan      html  css  js  c++  java
  • Linq101-Quantifiers

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 
     5 namespace Linq101
     6 {
     7     class Quantifiers
     8     {
     9         /// <summary>
    10         /// This sample uses Any to determine if any of the words in the array contain the substring 'ei'.
    11         /// </summary>
    12         public void Linq67()
    13         {
    14             string[] words = { "believe", "relief", "receipt", "field" };
    15 
    16             bool iAfterE = words.Any(w => w.Contains("ei"));
    17 
    18             Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
    19         }
    20 
    21         /// <summary>
    22         /// This sample uses Any to return a grouped a list of products only for categories that have at least one product that is out of stock.
    23         /// </summary>
    24         public void Linq68()
    25         {
    26             List<Data.Product> products = Data.GetProductList();
    27             var productGroups = from p in products
    28                                 group p by p.Category
    29                                     into g
    30                                     where g.Any(p => p.UnitsInStock == 0)
    31                                     select new { Category = g.Key, Products = g };
    32 
    33             ObjectDumper.Write(productGroups, 1);
    34         }
    35 
    36         /// <summary>
    37         /// This sample uses All to determine whether an array contains only odd numbers.
    38         /// </summary>
    39         public void Linq69()
    40         {
    41             int[] numbers = { 1, 11, 3, 19, 41, 65, 19 };
    42 
    43             bool onlyOdd = numbers.All(n => n % 2 == 1);
    44 
    45             Console.WriteLine("The list contains only odd numbers : {0}", onlyOdd);
    46         }
    47 
    48         /// <summary>
    49         /// This sample uses All to return a grouped a list of products only for categories that have all of their products in stock.
    50         /// </summary>
    51         public void Linq70()
    52         {
    53             List<Data.Product> products = Data.GetProductList();
    54 
    55             var productGroups = from p in products
    56                                 group p by p.Category
    57                                     into g
    58                                     where g.All(p => p.UnitsInStock > 0)
    59                                     select new { Category = g.Key, products = g };
    60 
    61             ObjectDumper.Write(productGroups, 1);
    62         }
    63     }
    64 }
  • 相关阅读:
    大话位运算
    Docker部署jar包
    linux系统备份mysql数据库
    关于Centos7 firewalld防火墙开放端口后仍不能访问ftp和nginx的问题解决
    MySql查询当天、本周、本月、本季度、本年的数据
    c#模拟线性回归
    监控服务器配置(五)-----Redis_exporter安装配置
    监控服务器配置(二)-----Grafana安装配置
    监控服务器配置(三)-----Node_exporter安装配置
    js网页唤起支付宝进行支付
  • 原文地址:https://www.cnblogs.com/David-Huang/p/4332556.html
Copyright © 2011-2022 走看看