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. 单例-b

    这个比较老了,是mrc 里面的 此例以模仿Apple官方文档的单例写出来的.但是一直有一个非常不明白的地方,就是alloc与allocWithZone:的重载中,为什么要return [[self c ...

  2. Java中的自动拆箱装箱(Autoboxing&Unboxing)

    一.基本类型打包器 1.基本类型:long.int.double.float.boolean 2.类类型:Long.Integer.Double.Float.Boolean 区别:基本类型效率更高,类 ...

  3. 重构oceanbase的一个函数

    我去,今天读了一下ob的源码,感觉有点乱啊!!!好吧,当作练手,我重构了一个函数 void* ObMySQLCallback::decode(easy_message_t* m) { uint32_t ...

  4. BZOJ 1027 合金

    Description 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的 ...

  5. 玩玩TCPCOPY+ intercept+mysql-replay-module(未成功)

    TCPCOPY+ intercept这两个模拟流量转发倒简单. 但,想实现一个mysql-replay-module模块时,失败了.(我现在仔细想想,这个方案,在我们现在的场景里,实用性不大,但弄好点 ...

  6. [C#] - 注入DLL

    原文:http://xyzlht.blog.163.com/blog/static/69301417200882834211787/ ) { MessageBox.Show("创建远程线程失 ...

  7. CSS样式中字体乱码

    今天写程序时,明明设置了label标签的属性font-family:"微软雅黑"的,但是字体的显示的效果就是宋体,后来查看了一下网页源代码,结果发现设置的字体为中文的都是乱码,难怪 ...

  8. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  9. ToArray()和IEnumerable<T>,List<T>

    一:ToArray() 在程序中,我们往往习惯使用List<>这种集合类,但是程序中却要求需要传递一个数组,List<>已经为我们提供了toArray()方法 二:IEnume ...

  10. 2012蓝桥杯本科组C/C++预赛题

    微生物增殖 假设有两种微生物 X 和 Y X出生后每隔3分钟分裂一次(数目加倍),Y出生后每隔2分钟分裂一次(数目加倍). 一个新出生的X,半分钟之后吃掉1个Y,并且,从此开始,每隔1分钟吃1个Y. ...