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. 排他锁Lock

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. duplicate symbols for architecture arm64 (Xcode error)

    比如 duplicate symbol _NewBase64Encode_soomla in: /Users/UnityGame/Libraries/Plugins/iOS/Soomla/libSoo ...

  3. JavaScript的应用

    DOM, BOM, XMLHttpRequest, Framework, Tool (Functionality) Performance (Caching, Combine, Minify, JSL ...

  4. Qt之自定义托盘(两种方法)

    http://www.cnblogs.com/swarmbees/p/5789482.html http://www.cnblogs.com/swarmbees/p/5812031.html

  5. Git批量修改提交历史

    有些时候我们可能需要批量修改提交历史,当然了,最近一次的提交历史很简单我们可以利用 git commit --amend 来进行最近一次提交的修改,如果你此时想要更新作者提交时间等也可以在amend之 ...

  6. 实战weblogic集群之安装weblogic

    一.系统及软件版本 OS版本:Red Hat Enterprise Linux Server release 6.6WebLogic Server 版本: 10.3.3.0JDK版本:1.7.0_79 ...

  7. 3 B. Lorry

    题目大意:给你两种物品,每种物品有一个价值和花费,花费只有两种,一种花费为 , 一种花费为2.. 给你一个背包容量为v, 求当前容量下所能达到的最大价值. ====================== ...

  8. 科研论文提交流程与常见问题(EDAS 系统提交)

    第一步 注册文章(Registering your Paper) 如上图,点击菜单中的submit paper按钮,会列出所有的会议和期刊,选择一个你要投稿的期刊或者会议,例如选择第一个2013 IE ...

  9. 高效算法——C 分饼

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  10. UVALive4513 Stammering Aliens(哈希法,后缀数组)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=12580 [思路] 求出现次数不小于k次的最长可重叠子串和最后的出现 ...