1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 5 namespace Linq101 6 { 7 class Miscellaneous 8 { 9 /// <summary> 10 /// This sample uses Concat to create one sequence that contains each array's values, one after the other. 11 /// </summary> 12 public void Linq94() 13 { 14 int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 }; 15 int[] numbersB = { 1, 3, 5, 7, 8 }; 16 17 var allNumbers = numbersA.Concat(numbersB); 18 19 Console.WriteLine("All numbers from both arrays:"); 20 21 foreach (int number in allNumbers) 22 { 23 Console.WriteLine(number); 24 } 25 } 26 27 /// <summary> 28 /// This sample uses Concat to create one sequence that contains the names of all customers and products, including any duplicates. 29 /// </summary> 30 public void Linq95() 31 { 32 List<Data.Customer> customers = Data.GetCustomerList(); 33 List<Data.Product> products = Data.GetProductList(); 34 35 var customerNames = from c in customers 36 select c.CompanyName; 37 var productNames = from p in products 38 select p.ProductName; 39 40 var allNames = customerNames.Concat(productNames); 41 42 Console.WriteLine("Customer and product names:"); 43 44 foreach (string name in allNames) 45 { 46 Console.WriteLine(name); 47 } 48 } 49 50 /// <summary> 51 /// This sample uses EqualAll to see if two sequences match on all elements in the same order. 52 /// </summary> 53 public void Linq96() 54 { 55 var wordsA = new[] { "cherry", "apple", "blueberry" }; 56 var wordsB = new[] { "cherry", "apple", "blueberry" }; 57 58 bool match = wordsA.SequenceEqual(wordsB); 59 60 Console.WriteLine("The sequences match :{0}", match); 61 } 62 63 /// <summary> 64 /// This sample uses EqualAll to see if two sequences match on all elements in the same order. 65 /// </summary> 66 public void Linq97() 67 { 68 var wordsA = new[] { "cherry", "apple", "blueberry" }; 69 var wordsB = new[] { "apple", "blueberry", "cherry" }; 70 71 bool match = wordsA.SequenceEqual(wordsB); 72 73 Console.WriteLine("The sequences match: {0}", match); 74 } 75 } 76 }