using System;
using System.Linq; namespace Linq101
{
class Projection
{
/// <summary>
/// This sample uses select to produce a sequence of ints one higher than those in an existing array of ints.
/// </summary>
public void Linq6()
{
int[] numbers = { , , , , , , , , , }; var query = from n in numbers
select n + ; Console.WriteLine("Numbers + 1 :");
foreach (var i in query)
{
Console.WriteLine(i);
}
} /// <summary>
/// This sample uses select to return a sequence of just the names of a list of products.
/// </summary>
public void Linq7()
{
var products = Data.GetProductList(); var query = from p in products
select p.ProductName; Console.WriteLine("Product Names:");
foreach (var productName in query)
{
Console.WriteLine(productName);
}
} /// <summary>
/// This sample uses select to produce a sequence of strings representing the text version of a sequence of ints.
/// </summary>
public void Linq8()
{
int[] numbers = { , , , , , , , , , };
string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var query = from n in numbers
select strings[n]; Console.WriteLine("Number strings:");
foreach (var s in query)
{
Console.WriteLine(s);
}
} /// <summary>
/// This sample uses select to produce a sequence of the uppercase and lowercase versions of each word in the original array.
/// </summary>
public void Linq9()
{
string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" }; var query = from w in words
select new { U = w.ToUpper(), L = w.ToLower() }; Console.WriteLine("Results:");
foreach (var item in query)
{
Console.WriteLine("Uppercase:{0},Lowercase:{1}", item.U, item.L);
}
} /// <summary>
/// This sample uses select to produce a sequence containing text representations of digits and whether their length? is even or odd.
/// </summary>
public void Linq10()
{
int[] numbers = { , , , , , , , , , };
string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var query = from n in numbers
select new { Digit = strings[n], EorO = n % == ? "Even" : "Odd" }; Console.WriteLine("Results:");
foreach (var item in query)
{
Console.WriteLine("The digit {0} is {1}", item.Digit, item.EorO);
}
} /// <summary>
/// This sample uses select to produce a sequence containing some properties of Products, including UnitPrice which is renamed to Price in the resulting type.
/// </summary>
public void Linq11()
{
var products = Data.GetProductList(); var query = from p in products
select new { p.ProductName, p.Category, Price = p.UnitPrice }; Console.WriteLine("Product Info:");
foreach (var product in query)
{
Console.WriteLine("{0} is in the category {1} and cost {2} per unit", product.ProductName, product.Category, product.Price);
}
} /// <summary>
/// This sample uses an indexed Select clause to determine if the value of ints in an array match their position in the array.
/// </summary>
public void Linq12()
{
int[] numbers = { , , , , , , , , , }; var query = numbers.Select((n, index) => new { Num = n, InPlace = n == index }); Console.WriteLine("Number:In-place?");
foreach (var number in query)
{
Console.WriteLine("{0}:{1}", number.Num, number.InPlace);
}
} /// <summary>
/// This sample combines select and where to make a simple query that returns the text form of each digit less than 5.
/// </summary>
public void Linq13()
{
int[] numbers = { , , , , , , , , , };
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; var query = from n in numbers
where n <
select digits[n]; Console.WriteLine("Numbers < 5:");
foreach (var digit in query)
{
Console.WriteLine(digit);
}
} /// <summary>
/// This sample uses a compound from clause to make a query that returns all pairs of numbers from both arrays such that the number from numbersA is less than the number from numbersB.
/// </summary>
public void Linq14()
{
int[] numbersA = { , , , , , , };
int[] numbersB = { , , , , }; var query = from a in numbersA
from b in numbersB
where a < b
select new { a, b }; Console.WriteLine("Pairs where a < b");
foreach (var pair in query)
{
Console.WriteLine("{0} is less than {1}", pair.a, pair.b);
}
} /// <summary>
/// This sample uses a compound from clause to select all orders where the order total is less than 500.00.
/// </summary>
public void Linq15()
{
var customers = Data.GetCustomerList(); var query = from c in customers
from o in c.Orders
where o.Total <
select new { c.CustomerID, o.OrderID, o.Total }; ObjectDumper.Write(query);
} /// <summary>
/// This sample uses a compound from clause to select all orders where the order was made in 1998 or later.
/// </summary>
public void Linq16()
{
var customers = Data.GetCustomerList(); var query = from c in customers
from o in c.Orders
where o.OrderDate >= new DateTime(, , )
select new { c.CustomerID, o.OrderID, o.OrderDate }; ObjectDumper.Write(query);
} /// <summary>
/// This sample uses a compound from clause to select all orders where the order total is greater than 2000.00 and uses from assignment to avoid requesting the total twice.
/// </summary>
public void Linq17()
{
var customers = Data.GetCustomerList(); var query = from c in customers
from o in c.Orders
where o.Total >
select new { c.CustomerID, o.OrderID, o.Total }; ObjectDumper.Write(query);
} /// <summary>
/// This sample uses multiple from clauses so that filtering on customers can be done before selecting their orders. This makes the query more efficient by not selecting and then discarding orders for customers outside of Washington.
/// </summary>
public void Linq18()
{
var customers = Data.GetCustomerList(); //效率低
//var query = from c in customers
// from o in c.Orders
// where c.Region == "WA" && o.OrderDate >= new DateTime(1997, 1, 1)
// select new { c.CustomerID, o.OrderID }; var query = from c in customers
where c.Region == "WA"
from o in c.Orders
where o.OrderDate >= new DateTime(, , )
select new { c.CustomerID, o.OrderID }; ObjectDumper.Write(query);
} /// <summary>
/// This sample uses an indexed SelectMany clause to select all orders, while referring to customers by the order in which they are returned from the query.
/// </summary>
public void Linq19()
{
var customers = Data.GetCustomerList(); //var query = customers.SelectMany(c => c.Orders);
//var query = customers.SelectMany(c => c.Orders).Where(o => o.OrderDate >= new DateTime(1998, 1, 1));
var query =
customers.SelectMany(
(customer, index) =>
(customer.Orders.Select(o => "Customer #" + (index + ) + " has an order with OrderID " + o.OrderID))); ObjectDumper.Write(query);
}
}
}

Linq101-Projection的更多相关文章

  1. OpenCASCADE BRep Projection

    OpenCASCADE BRep Projection eryar@163.com 一网友发邮件问我下图所示的效果如何在OpenCASCADE中实现,我的想法是先构造出螺旋线,再将螺旋线投影到面上. ...

  2. 鱼眼模式(Fisheye projection)的软件实现

    简单实现 鱼眼模式(Fisheye)和普通的透视投影(Perspective projection),一个很大的区别就是鱼眼的投影算法是非线性的(non-linear),实际照相机的情况是在镜头外面包 ...

  3. 细谈Slick(6)- Projection:ProvenShape,强类型的Query结果类型

    在Slick官方文档中描述:连接后台数据库后,需要通过定义Projection,即def * 来进行具体库表列column的选择和排序.通过Projection我们可以选择库表中部分列.也可以增加一些 ...

  4. <转载> OpenGL Projection Matrix

    原文 OpenGL Projection Matrix Related Topics: OpenGL Transformation Overview Perspective Projection Or ...

  5. (转)投影矩阵的推导(Deriving Projection Matrices)

    转自:http://blog.csdn.net/gggg_ggg/article/details/45969499 本文乃<投影矩阵的推导>译文,原文地址为: http://www.cod ...

  6. inconsistent line count calculation in projection snapshot

    1.现象 在vs2013中,按Ctrl + E + D格式化.cshtml代码,vs2013系统崩溃.报:inconsistent line count calculation in projecti ...

  7. CAF(C++ actor framework)使用随笔(projection 用法)(一)

    最近干活在写毕设,用到了CAF,看了文档,发现了一些小坑,自己摸索写点随笔.(CAF的github网站 https://github.com/actor-framework/actor-framewo ...

  8. shadow projection

    1.概述 shadow projection,又可成为planar shadow, 这是一种非常简单的绘制阴影的方法. 主要应用的应用场景:物体在平面投射阴影. 主要思想:把阴影看作是物体在平面上的投 ...

  9. 重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding

    原文:重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding [源码下 ...

  10. Machine Learning/Random Projection

    这次突然打算写点dimension reduction的东西, 虽然可以从PCA, manifold learning之类的东西开始, 但很难用那些东西说出好玩的东西. 这次选择的是一个不太出名但很有 ...

随机推荐

  1. DaoImpl中实现查询分页-使用HibernateCallback来做更加方便

    /** * */ package com.wolfgang.dao; import java.sql.SQLException; import java.util.List; import org.h ...

  2. eclipse中tomcat内存溢出问题,报PermGen space

    场景 最近在eclipse中的tomcat服务器下放三个不同的应用程序,其中两个应用程序用到了各自的第三方jar包.刚开始时把这三个应用程序分别部署到各自的tomcat服务器运行,没问题.后来想通过第 ...

  3. 数据结构(并查集):COGS 260. [NOI2002] 银河英雄传说

    260. [NOI2002] 银河英雄传说 ★★☆   输入文件:galaxy.in   输出文件:galaxy.out   简单对比时间限制:5 s   内存限制:128 MB [问题描述] 公元五 ...

  4. 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...

  5. wxsqlite3的加密模块单独编译

    其实就是个编译过程,so easy,只是网上的方法各种,而且不是最新的,所以自己琢磨了. 1.从sqlite网站下载sqlite-amalgamation-xxx和sqlite-dll-win32-x ...

  6. Unable to load native-hadoop library解决思路

    最近试着搭建Hadoop,我使用的操作系统是Centos6.5,Hadoop版本是2.6.0. 在安装过程中总是出现:WARN util.NativeCodeLoader: Unable to loa ...

  7. JS JQuery Ajax 跨域 Post Soap webservice

    呵呵 最近做一些HTML5的项目, 对于前段开发, 相信大家会碰到一个常见问题, 那就是Javascript跨域访问的问题. 话不多说 直接重点 当前网站和Webservice部署在同一个domain ...

  8. C++ sizeof

    class A{ int a; char c; char b; }; class B{ char c; int a; char b; }; int main(int argc, char* argv[ ...

  9. javaweb开发过程中的地址写法

    凡是要表示web资源的地址,比如浏览器地址栏中,都是 /凡是要表示硬盘地址, 都是 \  public class ServletDemo1 extends HttpServlet { //实际开发过 ...

  10. java中的String.format使用

         format(String  format, Objece...  argues)函数相当于C语言中的printf函数,但是相对来说更灵活.      和C中的printf函数差不多,在fo ...