Linq101-Set
using System;
using System.Collections.Generic;
using System.Linq; namespace Linq101
{
class Set
{
/// <summary>
/// This sample uses Distinct to remove duplicate elements in a sequence of factors of 300.
/// </summary>
public void Linq46()
{
int[] factorsOf300 = { , , , , }; var uniqueFactors = factorsOf300.Distinct(); Console.WriteLine("300的因数:");
foreach (var factor in uniqueFactors)
{
Console.WriteLine(factor);
}
} /// <summary>
/// This sample uses Distinct to find the unique Category names.
/// </summary>
public void Linq47()
{
List<Data.Product> products = Data.GetProductList(); var categoryNames = (from p in products
select p.Category).Distinct(); Console.WriteLine("种类名称:");
ObjectDumper.Write(categoryNames);
} /// <summary>
/// This sample uses Union to create one sequence that contains the unique values from both arrays.
/// </summary>
public void Linq48()
{
int[] numbersA = { , , , , , , };
int[] numbersB = { , , , , }; var uniqueNumbers = numbersA.Union(numbersB); Console.WriteLine("Unique numbers from both arrays:");
ObjectDumper.Write(uniqueNumbers);
} /// <summary>
/// This sample uses Union to create one sequence that contains the unique first letter from both product and customer names.
/// </summary>
public void Linq49()
{
List<Data.Product> products = Data.GetProductList();
List<Data.Customer> customers = Data.GetCustomerList(); var productFirstChar = from p in products select p.ProductName[];
var customerFirstChar = from c in customers select c.CompanyName[]; var uniqueFirstChar = productFirstChar.Union(customerFirstChar); Console.WriteLine("Unique First Char:");
ObjectDumper.Write(uniqueFirstChar);
} /// <summary>
/// This sample uses Intersect to create one sequence that contains the common values shared by both arrays.
/// </summary>
public void Linq50()
{
int[] numbersA = { , , , , , , };
int[] numbersB = { , , , , }; var commonNumbers = numbersA.Intersect(numbersB); Console.WriteLine("共有的数字:");
ObjectDumper.Write(commonNumbers);
} /// <summary>
/// This sample uses Intersect to create one sequence that contains the common first letter from both product and customer names.
/// </summary>
public void Linq51()
{
List<Data.Product> products = Data.GetProductList();
List<Data.Customer> customers = Data.GetCustomerList(); var productFirstChar = from p in products select p.ProductName[];
var customerFirstChar = from c in customers select c.CompanyName[]; var commonFirstChar = productFirstChar.Intersect(customerFirstChar); Console.WriteLine("Common First Char");
ObjectDumper.Write(commonFirstChar);
} /// <summary>
/// This sample uses Except to create a sequence that contains the values from numbersAthat are not also in numbersB.
/// </summary>
public void Linq52()
{
int[] numbersA = { , , , , , , };
int[] numbersB = { , , , , }; var aOnlyNumbers = numbersA.Except(numbersB); Console.WriteLine("Numbers in arrayA but no ArrayB");
ObjectDumper.Write(aOnlyNumbers);
} /// <summary>
/// This sample uses Except to create one sequence that contains the first letters of product names that are not also first letters of customer names.
/// </summary>
public void Linq53()
{
List<Data.Product> products = Data.GetProductList();
List<Data.Customer> customers = Data.GetCustomerList(); var productFirstChar = from p in products select p.ProductName[];
var customerFirstChar = from c in customers select c.CompanyName[]; var productOnlyFirstChar = productFirstChar.Except(customerFirstChar); Console.WriteLine("First char only in productFirstChar");
ObjectDumper.Write(productOnlyFirstChar);
}
}
}
Linq101-Set的更多相关文章
- Linq 101 工具和源码
工具如图: 源码: https://git.oschina.net/yudaming/Linq101
- 101个LINQ示例,包含几乎全部操作
Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...
- LINQ 101——约束、投影、排序
什么是LINQ:LINQ 是一组 .NET Framework 扩展模块集合,内含语言集成查询.集合以及转换操作.它使用查询的本机语言语法来扩展 C# 和 Visual Basic,并提供利用这些功能 ...
- Linq101-Join
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { internal clas ...
- Linq101-QueryExecution
using System; using System.Linq; namespace Linq101 { class QueryExecution { /// <summary> /// ...
- Linq101-CustomSequence
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class CustomS ...
- Linq101-Miscellaneous
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Miscell ...
- Linq101-Aggregate
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Aggrega ...
- Linq101-Quantifiers
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Quantif ...
- Linq101-Generation
using System; using System.Linq; namespace Linq101 { class Generation { /// <summary> /// This ...
随机推荐
- BZOJ 1006 神奇的国度
Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系 ...
- 获取Delphi所有类的类信息
Delphi遍历进程中所有Class的TypeInfo,即便是在implementation中的class或者其他 class的private的子class. 一般普通EXE中的TypeInfo存放在 ...
- 两个div之间有空隙
加句*{ margin:0; padding:0;} 最近在做网页时发现,在IE7下(FF没试过),div与div之间有时会出20个像素左右的空隙,除非把margin设成负值,否则空隙无法去除.我在 ...
- 字符串(后缀数组||SAM):NOI2015 品酒大会
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAByIAAALuCAIAAABtq0bwAAAgAElEQVR4nOy9f2wb150vev4boESeln ...
- UVa11613 Acme Corporation(最小费用流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33452 [思路] 最小费用流. 构图: 1 每个月建立2个点,建立 ...
- 《Mathematical Olympiad——数论》——整除
数论这个东西吧,虽说也是高中IMOer玩的数学游戏,颇具美学性的证明比较多.就目前所知,它在算法里是一些加密技术的基础,不多言,开始具体题目的分析. 问题一:已知数列{an},且a0 = 2 , a1 ...
- Timeout for tests
如果想把timeout太久的测试自动标记为失败,有两种方法: 1.在 @Test里加上 Timeout 参数 定义"timeout=1000“的话,如果超过1000 毫秒,failure会被 ...
- poj1013
题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...
- MongoDB 逻辑与操作
看下面两个例子 rs1:PRIMARY> db.display.find({$and: [{$where: '(1386813645 - this.last_active_time > 3 ...
- Core OS 层
Core OS层的底层功能是很多其他技术的构建基础.通常情况下,这些功能不会直接应用于应用程序,而是应用于其他框架.但是,在直接处理安全事务或和某个外设通讯的时候,则必须要应用到该层的框架. Acce ...