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 ...
随机推荐
- [BZOJ 1816] [Cqoi2010] 扑克牌 【二分答案】
题目链接:BZOJ - 1816 题目分析 答案具有可以二分的性质,所以可以二分答案. 验证一个答案 x 是否可行,就累加一下各种牌相对于 x 还缺少的量,如果总和超过了 x 或 m ,就不可行. 因 ...
- [BZOJ 2243] [SDOI 2011] 染色 【树链剖分】
题目链接:BZOJ - 2243 题目分析 树链剖分...写了200+行...Debug了整整一天+... 静态读代码读了 5 遍 ,没发现错误,自己做小数据也过了. 提交之后全 WA . ————— ...
- java打jar包 命令行cmd在当前路径打jar包
不尝试就永远不会知道真相. 今天搞webservice,需要将服务单独拉出来发布.打jar包的时候要打成aar包,所以用到cmd下的打jar包的命令. 当前路径打jar包,一定要先进到这个文件夹,然后 ...
- GCD - Extreme (II)
uva11424: 题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gc ...
- visualvm监控jvm及远程jvm监控方法(转)
VisualVM是Sun的一个OpenJDK项目,其目的在于为Java应用创建一个整套的问题解决工具.它集成了多个JDK命令工具的一个可视化工具,它主要用来监控JVM的运行情况,可以用它来查看和浏览H ...
- BZOJ1611: [Usaco2008 Feb]Meteor Shower流星雨
1611: [Usaco2008 Feb]Meteor Shower流星雨 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 904 Solved: 393 ...
- Linux Shell编程(6)——变量替换
变量的名字是它的值保存的地方.引用它的值称为变量替换.$让我们仔细地区别变量和变量的值.如果variable1是一个变量的名字,那么$variable1就是引用这个变量的值――即这个变量它包含的数据. ...
- selenuim ide回放时出现的问题
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-core/scripts/htm ...
- 什么是:VGA SVGA XGA SXGA
经常可以看到VGA这些专业术语,通常这些重要技术指标指的是液晶屏(TFT LCD)的分辨率. TFT是英文Thin Film Transistor的缩写,中文意思是薄膜晶体管. VGA(Video G ...
- python数据的存储和持久化操作
Python的数据持久化操作主要是六类:普通文件.DBM文件.Pickled对象存储.shelve对象存储.对象数据库存储.关系数据库存储. 普通文件不解释了,DBM就是把字符串的键值对存储在文件里: ...