Linq101-Element
using System;
using System.Collections.Generic;
using System.Linq; namespace Linq101
{
class Element
{
/// <summary>
/// This sample uses First to return the first matching element as a Product, instead of as a sequence containing a Product.
/// </summary>
public void Linq58()
{
List<Data.Product> products = Data.GetProductList(); Data.Product product12 = (from p in products
where p.ProductID ==
select p).First(); ObjectDumper.Write(product12);
} /// <summary>
/// This sample uses First to find the first element in the array that starts with 'o'.
/// </summary>
public void Linq59()
{
string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; string startsWithO = strings.First(s => s[] == 'o'); Console.WriteLine("A string starting with 'o': {0}", startsWithO);
} /// <summary>
/// This sample uses FirstOrDefault to try to return the first element of the sequence, unless there are no elements, in which case the default value for that type is returned.
/// </summary>
public void Linq60()
{
int[] numbers = { }; int firstNumOrDefault = numbers.FirstOrDefault(); Console.WriteLine(firstNumOrDefault);
} /// <summary>
/// This sample uses FirstOrDefault to return the first product whose ProductID is 789 as a single Product object, unless there is no match, in which case null is returned.
/// </summary>
public void Linq61()
{
List<Data.Product> products = Data.GetProductList(); Data.Product product789 = products.FirstOrDefault(p => p.ProductID == ); Console.WriteLine("Product 789 exists: {0}", product789 != null);
} /// <summary>
/// This sample uses ElementAt to retrieve the second number greater than 5 from an array.
/// </summary>
public void Linq62()
{
int[] numbers = { , , , , , , , , , }; int number = (from n in numbers
where n >
select n).ElementAt(); Console.WriteLine("Second number > 5: {0}", number);
}
}
}
Linq101-Element的更多相关文章
- Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .
例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...
- 【解决方案】cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-role-r
[JAVA错误] cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One o ...
- WebComponent魔法堂:深究Custom Element 之 从过去看现在
前言 说起Custom Element那必然会想起那个相似而又以失败告终的HTML Component.HTML Component是在IE5开始引入的新技术,用于对原生元素作功能"增强& ...
- WebComponent魔法堂:深究Custom Element 之 标准构建
前言 通过<WebComponent魔法堂:深究Custom Element 之 面向痛点编程>,我们明白到其实Custom Element并不是什么新东西,我们甚至可以在IE5.5上定 ...
- WebComponent魔法堂:深究Custom Element 之 面向痛点编程
前言 最近加入到新项目组负责前端技术预研和选型,一直偏向于以Polymer为代表的WebComponent技术线,于是查阅各类资料想说服老大向这方面靠,最后得到的结果是:"资料99%是英语 ...
- 深入理解DOM节点类型第五篇——元素节点Element
× 目录 [1]特征 [2]子节点 [3]特性操作[4]attributes 前面的话 元素节点Element非常常用,是DOM文档树的主要节点:元素节点是html标签元素的DOM化结果.元素节点主要 ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
spring 配置文件报错报错信息:cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be ...
- MongoDB查询转对象是出错Element '_id' does not match any field or property of class
MongoDB查询转对象是出错Element '_id' does not match any field or property of class 解决方法: 1.在实体类加:[BsonIgno ...
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
- [LeetCode] Kth Smallest Element in a BST 二叉搜索树中的第K小的元素
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
随机推荐
- Instagram的技术架构
http://blogread.cn/it/article/5497 Instagram 被 Facebook 以10亿美金收购.团队规模:13 人.而在被Facebook收购前的一个月,整个团队才7 ...
- The Child and Toy
Codeforces Round #250 (Div. 2) C:http://codeforces.com/problemset/problem/437/C 题意:给以一个无向图,每个点都有一点的权 ...
- 静态与动态IP设置
静态IP设置 netsh interface ipv4 set address name="本地连接" source=static addr=192.168.0.212 (这个地方 ...
- BAT 批处理实现循环备份N天文件夹
@echo off set today=%date:~0,4%%date:~5,2%%date:~8,2% xcopy /E /I E:\aaa e:\test\%today% for /f &qu ...
- 【HDOJ】5128
暴力+计算几何. /* 5128 */ #include <iostream> #include <algorithm> #include <cstdio> #in ...
- 数学(矩阵乘法):HDU 4565 So Easy!
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 图论(网络流):[SCOI2015]小凸玩矩阵
Description 小凸和小方是好朋友,小方给小凸一个N*M(N<=M)的矩阵A,要求小秃从其中选出N个数,其中任意两个数字不能在同一行或同一列,现小凸想知道选出来的N个数中第K大的数字的最 ...
- sharepoint2007的中文版
今天终于下载到了sharepoint2007的中文版了,以前微软的测试板也没有中文版,今天终于下载到了,经过测试,用英文版的sn也是可以用的.微软提供的测试版,输入正式的key,就可以变成正式版了.我 ...
- [FreeProxy]FreeProxy代理服务器端软件介绍 之 sock 5
首先在FreeProxy上创建一个sock5 service 然后在Client 设置使用sock5
- FZYZOJ-1880 【UFO】水管
P1880 -- [ufo]水管 时间限制:1000MS 内存限制:131072KB 通过/提交人数:32/100 状态: 标签: 数学问题-组合数学 无 ...