using System;
using System.Collections.Generic;
using System.Linq; namespace Linq101
{
class Quantifiers
{
/// <summary>
/// This sample uses Any to determine if any of the words in the array contain the substring 'ei'.
/// </summary>
public void Linq67()
{
string[] words = { "believe", "relief", "receipt", "field" }; bool iAfterE = words.Any(w => w.Contains("ei")); Console.WriteLine("There is a word that contains in the list that contains 'ei': {0}", iAfterE);
} /// <summary>
/// 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.
/// </summary>
public void Linq68()
{
List<Data.Product> products = Data.GetProductList();
var productGroups = from p in products
group p by p.Category
into g
where g.Any(p => p.UnitsInStock == )
select new { Category = g.Key, Products = g }; ObjectDumper.Write(productGroups, );
} /// <summary>
/// This sample uses All to determine whether an array contains only odd numbers.
/// </summary>
public void Linq69()
{
int[] numbers = { , , , , , , }; bool onlyOdd = numbers.All(n => n % == ); Console.WriteLine("The list contains only odd numbers : {0}", onlyOdd);
} /// <summary>
/// This sample uses All to return a grouped a list of products only for categories that have all of their products in stock.
/// </summary>
public void Linq70()
{
List<Data.Product> products = Data.GetProductList(); var productGroups = from p in products
group p by p.Category
into g
where g.All(p => p.UnitsInStock > )
select new { Category = g.Key, products = g }; ObjectDumper.Write(productGroups, );
}
}
}

Linq101-Quantifiers的更多相关文章

  1. 6-1 Quantifiers

    1 Quantifiers are used to describe the number or amount of something. Certain quantifiers are used w ...

  2. Discrete Mathematics and Its Applications | 1 CHAPTER The Foundations: Logic and Proofs | 1.4 Predicates and Quantifiers

    The statements that describe valid input are known as preconditions and the conditions that the outp ...

  3. 正则表达式中的Quantifiers

    ?: Match an element zero or one time 例如: colou?r: color 或 colour 但不能是 colo2r *: Match an element zer ...

  4. 101个LINQ示例,包含几乎全部操作

    Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...

  5. Linq编程101例

    原文地址:101 LINQ Samples in C# Part1 - Restriction Operators Part2 - Projection Operators Part3 - Parti ...

  6. 原生JS:RegExp对象详解

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  7. 《Java学习笔记(第8版)》学习指导

    <Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多 ...

  8. C#基础知识简单梳理

    本文是转发博友的总结,方便自己以后随时温习: 1.值类型和引用类型 1.1堆和栈 简单的说值类型存放在堆栈上面,引用类型的数据存放在托管堆上面(它的引用地址却存放在堆栈上面)! 栈:它是一个内存数组, ...

  9. PHP正则表达式详解(一)

    前言: 半年前我对正则表达式产生了兴趣,在网上查找过不少资料,看过不少的教程,最后在使用一个正则表达式工具RegexBuddy时,发现他的教程写的非常好,可以说是我目前见过最好的正则表达式教程.于是一 ...

随机推荐

  1. iscc2016-basic-明察秋毫

    查看源代码,找到maybe not flag : Jr1p0zr2VfPp 移位密码,注意判断字母大小写,并且数字无变化 s = "Jr1p0zr2VfPp" p = list(s ...

  2. BZOJ 1011 遥远的行星

    Description 直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故 ...

  3. Java吸收换行符

            今天做题遇到的--         由于读入的字符串可能包含空格,所以采用nextLine. int n = sc.nextInt(); for(int i=0; i<n; i+ ...

  4. 基于 SWTBot 进行 Eclipse GUI 自动化测试

    背景简介 在软件开发领域,持续集成和部署对于软件测试自动化提出了越来越高的要求,基于 Eclipse 应用在这一需求中仍然占据重要的组成部分.目前主流的测试自动化工具主要以录制回放的功能为主,辅助以脚 ...

  5. LINUX-LXC要好好关注下

    因为我觉得轻量极虚拟化可能是云的另一个发展方向. 至少,腾讯的WEB云引擎是以此为基础. LXC结合DOCKER.相信是快速云的另一种实现. 余下的,只是结合生产系统围绕这一中心进行的的二次开了. I ...

  6. sicp第1章

    牛顿迭代法求平方: (define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) ...

  7. AlgorithmsI PA2: Randomized Queues and Deques Subset

    本题的bonus是 因此方法是queue的size 达到了K, 就停止增加元素,保证queue.size() 最大时只有k. Java code: import edu.princeton.cs.al ...

  8. 更改Visual Studio 2010/2012/2008的主题设置

    一.更改主题: 主题网站:http://studiostyl.es/ Visual Studio 2010发布也已经有一段时间了,不过安装后默认的白底的主题长时间看代码可能会感觉眼睛酸痛,况且时间长了 ...

  9. java一切乱码的解释 以及源头【转】

    工作中经常遇到java编码问题,由于缺乏研究,总是无法给出确切的答案,这个周末在网上查了一些资料,在此做些汇总. 问题一:在java中读取文件时应该采用什么编码? Java读取文件的方式总体可以分为两 ...

  10. cf703A Mishka and Game

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...