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的更多相关文章

  1. Linq 101 工具和源码

    工具如图: 源码: https://git.oschina.net/yudaming/Linq101

  2. 101个LINQ示例,包含几乎全部操作

    Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...

  3. LINQ 101——约束、投影、排序

    什么是LINQ:LINQ 是一组 .NET Framework 扩展模块集合,内含语言集成查询.集合以及转换操作.它使用查询的本机语言语法来扩展 C# 和 Visual Basic,并提供利用这些功能 ...

  4. Linq101-Join

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { internal clas ...

  5. Linq101-QueryExecution

    using System; using System.Linq; namespace Linq101 { class QueryExecution { /// <summary> /// ...

  6. Linq101-CustomSequence

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class CustomS ...

  7. Linq101-Miscellaneous

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Miscell ...

  8. Linq101-Aggregate

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Aggrega ...

  9. Linq101-Quantifiers

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Quantif ...

  10. Linq101-Generation

    using System; using System.Linq; namespace Linq101 { class Generation { /// <summary> /// This ...

随机推荐

  1. UIview lianxi

    // 创建一个和屏幕大小相同的window,记住[UIScreen mainScreen].bounds 是获取当前屏幕大小 self.window = [[[UIWindow alloc] init ...

  2. c# appdomain

    http://www.cnblogs.com/Terrylee/archive/2005/11/28/285809.html

  3. 专家解读Linux操作系统内核中的GCC特性

    专家解读Linux操作系统内核中的GCC特性   Linux内核使用GNU Compiler Collection (GCC)套件的几个特殊功能.这些功能包括提供快捷方式和简化以及向编译器提供优化提示 ...

  4. 见过NTP服务,没见过网络流量到200M左右的NTP服务

    XXX,看来可能是NTP.CONF的文件配置错误所致了. 附上一段查看网络流量的SHELL.(好像只针对ETH0,如果要看其它的,还需要修改) #!/bin/bash typeset in_old d ...

  5. Unity 地形

    创建一个地形: GameObject —> Create Other —> Terrain; 地形的属性设置:(部分属性后面有另说,表示其他作者有说明过的内容) Base Terrain( ...

  6. Qt入门(11)——Qt插件

    Qt提供了一个简单地插件接口,可以轻松地生成作为独立组件的定制数据库驱动.图象格式.文本编解码器(text codec).风格(style)和部件.警告:Qt 3.0.5对插件的一些方面做了改变,具体 ...

  7. 动态规划(背包问题):POJ 1742 Coins

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 32955   Accepted: 11199 Descripti ...

  8. 【贪心】CSU 1809 Parenthesis (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 题目大意: 给一个长度为N(N<=105)的合法括号序列.Q(Q<= ...

  9. Eclipse 在线汉化

    1. 打开Eclipse  , 进入菜单中 Help-->Install new Software.. 2. 到Eclipse 官网找到语言包地址,http://www.eclipse.org/ ...

  10. Hadoop入门--HDFS(单节点)配置和部署 (一)

    一 配置SSH 下载ssh服务端和客户端 sudo apt-get install openssh-server openssh-client 验证是否安装成功 ssh username@192.16 ...