Concat - 1
This sample uses Concat to create one sequence that contains each array's values, one after the other.
- 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 (var n in allNumbers)
- {
- Console.WriteLine(n);
- }
- }
Result
All numbers from both arrays:
0
2
4
5
6
8
9
1
3
5
7
8
Concat - 2
This sample uses Concat to create one sequence that contains the names of all customers and products, including any duplicates.
- public void Linq95()
- {
- List<Customer> customers = GetCustomerList();
- List<Product> products = 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 (var n in allNames)
- {
- Console.WriteLine(n);
- }
- }
Result
Customer and product names:
Alfreds Futterkiste
Ana Trujillo Emparedados y helados
Antonio Moreno TaquerÃa
Around the Horn
Berglunds snabbköp
Blauer See Delikatessen
Blondel père et fils
Bólido Comidas preparadas
Bon app'
Bottom-Dollar Markets
B's Beverages
Cactus Comidas para llevar
Centro comercial Moctezuma
Chop-suey Chinese
Comércio Mineiro
Consolidated Holdings
Drachenblut Delikatessen
Du monde entier
Eastern Connection
Ernst Handel
Familia Arquibaldo
FISSA Fabrica Inter. Salchichas S.A.
Folies gourmandes
Folk och fä HB
Frankenversand
France restauration
Franchi S.p.A.
Furia Bacalhau e Frutos do Mar
GalerÃa del gastrónomo
Godos Cocina TÃpica
Gourmet Lanchonetes
Great Lakes Food Market
GROSELLA-Restaurante
Hanari Carnes
HILARIÓN-Abastos
Hungry Coyote Import Store
Hungry Owl All-Night Grocers
Island Trading
Königlich Essen
La corne d'abondance
La maison d'Asie
Laughing Bacchus Wine Cellars
Lazy K Kountry Store
Lehmanns Marktstand
Let's Stop N Shop
LILA-Supermercado
LINO-Delicateses
Lonesome Pine Restaurant
Magazzini Alimentari Riuniti
Maison Dewey Mère Paillarde
Morgenstern Gesundkost
North/South
Océano Atlántico Ltda.
Old World Delicatessen
Ottilies Käseladen
Paris spécialités
Pericles Comidas clásicas
Piccolo und mehr
Princesa Isabel Vinhos
Que DelÃcia
Queen Cozinha
QUICK-Stop
Rancho grande
Rattlesnake Canyon Grocery
Reggiani Caseifici
Ricardo Adocicados
Richter Supermarkt
Romero y tomillo Santé Gourmet
Save-a-lot Markets
Seven Seas Imports
Simons bistro
Spécialités du monde
Split Rail Beer & Ale
Suprêmes délices
The Big Cheese
The Cracker Box
Toms Spezialitäten
Tortuga Restaurante
Tradição Hipermercados
Trail's Head Gourmet Provisioners
Vaffeljernet
Victuailles en stock
Vins et alcools Chevalier
Die Wandernde Kuh
Wartian Herkku
Wellington Importadora
White Clover Markets
Wilman Kala
Wolski Zajazd
Chai
Chang
Aniseed Syrup
Chef Anton's Cajun Seasoning
Chef Anton's Gumbo Mix
Grandma's Boysenberry Spread
Uncle Bob's Organic Dried Pears
Northwoods Cranberry Sauce
Mishi Kobe Niku
Ikura
Queso Cabrales
Queso Manchego La Pastora
Konbu
Tofu
Genen Shouyu
Pavlova
Alice Mutton
Carnarvon Tigers
Teatime Chocolate Biscuits
Sir Rodney's Marmalade
Sir Rodney's Scones
Gustaf's Knäckebröd
Tunnbröd
Guaraná Fantástica
NuNuCa Nuß-Nougat-Creme
Gumbär Gummibärchen
Schoggi Schokolade
Rössle Sauerkraut
Thüringer Rostbratwurst
Nord-Ost Matjeshering
Gorgonzola Telino
Mascarpone Fabioli
Geitost
Sasquatch Ale
Steeleye Stout
Inlagd Sill
Gravad lax
Côte de Blaye
Chartreuse verte
Boston Crab Meat
Jack's New England Clam Chowder
Singaporean Hokkien Fried Mee
Ipoh Coffee
Gula Malacca
Rogede sild
Spegesild
Zaanse koeken
Chocolade
Maxilaku
Valkoinen suklaa
Manjimup Dried Apples
Filo Mix
Perth Pasties
Tourtière
Pâté chinois
Gnocchi di nonna Alice
Ravioli Angelo
Escargots de Bourgogne
Raclette Courdavault
Camembert Pierrot
Sirop d'érable
Tarte au sucre
Vegie-spread
Wimmers gute Semmelknödel
Louisiana Fiery Hot Pepper Sauce
Louisiana Hot Spiced Okra
Laughing Lumberjack Lager
Scottish Longbreads
Gudbrandsdalsost
Outback Lager
Flotemysost
Mozzarella di Giovanni
Röd Kaviar
Longlife Tofu
Rhönbräu Klosterbier
Lakkalikööri
Original Frankfurter grüne Soße
EqualAll - 1
This sample uses EqualAll to see if two sequences match on all elements in the same order.
- public void Linq96()
- {
- var wordsA = new string[] { "cherry", "apple", "blueberry" };
- var wordsB = new string[] { "cherry", "apple", "blueberry" };
-
- bool match = wordsA.SequenceEqual(wordsB);
-
- Console.WriteLine("The sequences match: {0}", match);
- }
Result
The sequences match: True
EqualAll - 2
This sample uses EqualAll to see if two sequences match on all elements in the same order.
- public void Linq97()
- {
- var wordsA = new string[] { "cherry", "apple", "blueberry" };
- var wordsB = new string[] { "apple", "blueberry", "cherry" };
-
- bool match = wordsA.SequenceEqual(wordsB);
-
- Console.WriteLine("The sequences match: {0}", match);
- }
Result
The sequences match: False