Linq101-Miscellaneous
2015-04-22 15:15
190 查看
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Miscellaneous { /// <summary> /// This sample uses Concat to create one sequence that contains each array's values, one after the other. /// </summary> public void Linq94() { int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 }; int[] numbersB = { 1, 3, 5, 7, 8 }; var allNumbers = numbersA.Concat(numbersB); Console.WriteLine("All numbers from both arrays:"); foreach (int number in allNumbers) { Console.WriteLine(number); } } /// <summary> /// This sample uses Concat to create one sequence that contains the names of all customers and products, including any duplicates. /// </summary> public void Linq95() { List<Data.Customer> customers = Data.GetCustomerList(); List<Data.Product> products = Data.GetProductList(); var customerNames = from c in customers select c.CompanyName; var productNames = from p in products select p.ProductName; var allNames = customerNames.Concat(productNames); Console.WriteLine("Customer and product names:"); foreach (string name in allNames) { Console.WriteLine(name); } } /// <summary> /// This sample uses EqualAll to see if two sequences match on all elements in the same order. /// </summary> public void Linq96() { var wordsA = new[] { "cherry", "apple", "blueberry" }; var wordsB = new[] { "cherry", "apple", "blueberry" }; bool match = wordsA.SequenceEqual(wordsB); Console.WriteLine("The sequences match :{0}", match); } /// <summary> /// This sample uses EqualAll to see if two sequences match on all elements in the same order. /// </summary> public void Linq97() { var wordsA = new[] { "cherry", "apple", "blueberry" }; var wordsB = new[] { "apple", "blueberry", "cherry" }; bool match = wordsA.SequenceEqual(wordsB); Console.WriteLine("The sequences match: {0}", match); } } }
相关文章推荐
- Linq101-Projection
- LINQ 101例子
- Linq101-Restriction
- 101 LINQ Samples(from MSDN)
- Linq101-Ordering
- linq 的查询的学习 (google 中输入 101 linq) -- select的应用
- 101 LINQ Samples(from MSDN)
- Linq101-Partitioning
- Linq101-CustomSequence
- Linq 101 工具和源码
- 【编译】StreamInsight的LINQ示例101
- Linq101-Grouping Operators
- 101 LINQ Samples
- Linq101-Quantifiers
- Linq101-Set
- Linq101-Element
- Linq101-Join
- Linq101-Conversion Operators
- Linq101-Generation
- Linq101-QueryExecution