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 ...
随机推荐
- 2D地图随机生成
2D地图随机生成基础绘图 海陆分布
- TortoiseSVN 的分支合并操作
今天对svn的分支合并有了兴趣,所以对新建了一个项目练练手. 在网上找了一篇文章做指导: http://www.open-open.com/lib/view/open1346982569725.htm ...
- 14.5.2.3 Consistent Nonlocking Reads 一致性非锁定读
14.5.2.3 Consistent Nonlocking Reads 一致性非锁定读 一致性读意味着 InnoDB 使用多版本来实现一个查询数据库的快照在某个时间点. 查看看到的事务做出的改变被提 ...
- index unique scan
INDEX UNIQUE SCAN 索引唯一扫描.单块读 只可能发生在unique index/primary key 等值查找 等待事件:db file s ...
- a great tool for automatically formating your code!
1. make your own format file at your project's root or file's folder. (The clang-format will automat ...
- Linux Kernel 'dispatch_discard_io()'安全绕过漏洞
漏洞版本: Linux Kernel 漏洞描述: Bugtraq ID:60414 CVE ID:CVE-2013-2140 Linux是一款开源的操作系统. 由于不充分的检查BLKIF_OP_DIS ...
- Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest 状压DP
D. Little Pony and Harmony Chest Princess Twilight went to Celestia and Luna's old castle to resea ...
- Eclipse : 找不到或无法加载主类
问题: 找不到或无法加载主类 解决思路: Step1: 去网上百度了下,基本上都说是环境变量的问题. 原因:环境变量设置有问题. 解决方法:重设环境变量 结果:当然问题没解决. Step2:再次百度, ...
- 用Myeclipse 编写struts.xml时,自动提示
之所以不自动提示,是因为这个xml它不知道自己的xml格式是什么有哪些标签,所以不知道该怎么提示 所以就要给它引入格式,所以要引入XSD或者DTD文件 1.首先打开MyEclipse的窗口,选择“Wi ...
- 网络编程之TCP异步群聊:客户端代码
最近朋友建议我写一些关于微软云技术的博客留给学校下一届的学生们看,怕下一届的MSTC断档.于是我也觉的有这个必要.写了几篇博客之后,我觉得也有必要把这一年的学习内容放在博客做个纪念,就这样写了本篇博客 ...