Linq101-Quantifiers
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的更多相关文章
- 6-1 Quantifiers
1 Quantifiers are used to describe the number or amount of something. Certain quantifiers are used w ...
- 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 ...
- 正则表达式中的Quantifiers
?: Match an element zero or one time 例如: colou?r: color 或 colour 但不能是 colo2r *: Match an element zer ...
- 101个LINQ示例,包含几乎全部操作
Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...
- Linq编程101例
原文地址:101 LINQ Samples in C# Part1 - Restriction Operators Part2 - Projection Operators Part3 - Parti ...
- 原生JS:RegExp对象详解
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 《Java学习笔记(第8版)》学习指导
<Java学习笔记(第8版)>学习指导 目录 图书简况 学习指导 第一章 Java平台概论 第二章 从JDK到IDE 第三章 基础语法 第四章 认识对象 第五章 对象封装 第六章 继承与多 ...
- C#基础知识简单梳理
本文是转发博友的总结,方便自己以后随时温习: 1.值类型和引用类型 1.1堆和栈 简单的说值类型存放在堆栈上面,引用类型的数据存放在托管堆上面(它的引用地址却存放在堆栈上面)! 栈:它是一个内存数组, ...
- PHP正则表达式详解(一)
前言: 半年前我对正则表达式产生了兴趣,在网上查找过不少资料,看过不少的教程,最后在使用一个正则表达式工具RegexBuddy时,发现他的教程写的非常好,可以说是我目前见过最好的正则表达式教程.于是一 ...
随机推荐
- Java Socket Example
1.服务端:server package com.socket; import java.io.BufferedReader; import java.io.IOException; import j ...
- SharePoint 软件边界及限制
摘自technet http://technet.microsoft.com/zh-cn/library/cc262787.aspx
- Door man
poj1300:http://poj.org/problem?id=1300 题意:给你n个房间,房间之间有一些门,房间是按0~~n-进行编号的.然后给出一些房间的之间门,n行,每行的数字表示该们与其 ...
- VC版本的MakeObjectInstance把WNDPROC映射到类的成员函数
这段时间用VC封装Windows类库,没有MakeObjectInstance处理窗口消息确实不爽,又不想使用MFC的消息映射,这玩意的效率和美观只能呵呵. 至于MakeObjectInstance是 ...
- Gap Locks 区间锁
Gap Locks 区间锁 1. 区间锁不能用于语句锁定记录使用一个唯一索引来搜索一个唯一的记录 2.READ COMMITTED 没有区间锁 区间锁是一个锁在一个在index记录间的区间,或者一个l ...
- Tomcat死机报OutOfMemoryError: PermGen space错误
最近,用户没怎么使用系统,页面就卡死,访问不了.仔细一看是Tomcat假死,好几次都这样.重启也慢的很,很着急.最后,看了下 conf/logs 里的配置文件,发现是 OutOfMemoryError ...
- [已解决问题] Could not find class XXX referenced from method XXX.<YYY>
导入Jar包的问题,有时候即使引入了Jar包也会报错,比如我在引入了libsvm.jar后仍然会报此错 解决方法是: Step 1. 创建User library,随便命一个名,然后把Jar包导入 S ...
- jsp中的contentType与pageEncoding的区别和作用
jsp中的contentType与pageEncoding的区别和作用 <%@ page contentType="text/html; charset=utf-8" p ...
- [AS/400] Control Language
下面是一个简单的 CL 例子,转换日期格式:从 Julian 到 MDY,或者反方向转换. 接受两个参数,日期值 IN,目标类型 TYP,将转换后的日期值存入 OUT 中. PGM (&IN ...
- N - Is It A Tree?(判断环)
题意,就是判断这点点是不是组成的一颗树,也就是判断是否有环,就是没看出来如果是森林怎么办,试一试吧,最可恶的还没有说有多少节点.....就是个坑 /////////////////////////// ...