LINQSamples.com
  • Samples
  • Tutorials
  • About
  • Links
  • Contact
LINQ to Objects

Aggregation

Aggregate, Average, Count, LongCount, Max, Min, Sum

      Aggregate (simple)       Aggregate (seed)       Average       Count       LongCount       Max       Min       Sum

Conversion

AsEnumerable, Cast, OfType, ToArray, ToDictionary, ToList, ToLookup

      AsEnumerable       Cast       OfType       ToArray       ToDictionary (simple)       ToDictionary (conditional)       ToList       ToLookup

Element

ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault

      ElementAt       ElementAtOrDefault       First (simple)       First (conditional)       FirstOrDefault       Last       LastOrDefault (simple)       LastOrDefault (conditional)       Single       SingleOrDefault

Generation

DefaultIfEmpty, Empty, Range, Repeat

      DefaultIfEmpty (simple)       DefaultIfEmpty (default value)       Empty       Range       Repeat

Grouping

GroupBy

      GroupBy

Join

GroupJoin, Join

      GroupJoin (left outer join)       Join (inner join)

Ordering

OrderBy, OrderByDescending, Reverse, ThenBy, ThenByDescending

      OrderBy (simple - numbers)       OrderBy (simple - dates)       OrderBy (simple - objects)       OrderByDescending       Reverse       ThenBy       ThenByDescending

Other

Concat, SequenceEqual, Zip

      Concat (simple - numbers)       Concat (simple - strings)       SequenceEqual       Zip

Partitioning

Skip, SkipWhile, Take, TakeWhile

      Skip       SkipWhile       Take       TakeWhile

Projection

Select, SelectMany

      Select (simple)       Select (anonymous type)       Select (indexed)       SelectMany (cross join)

Quantifiers

All, Any, Contains

      All       Any       Contains

Restriction

Where

      Where (simple - numbers)       Where (simple - objects)       Where (indexed)

Set

Distinct, Except, Intersect, Union

      Distinct       Except       Intersect       Union
  Close

Concat (simple - strings)

Lambda Query

Concat: Concatenates (combines) two collections.

Concat: Concatenates (combines) two collections.

This Lambda Expression sample concatenates two arrays of strings.

This Lambda Expression sample concatenates two arrays of strings.

  • C#
  • VB.Net
  • F#
// A Query Expression cannot be constructed for Concat() in C#.
// Consider using a Lambda Expression instead.
' A Query Expression cannot be constructed for Concat() in VB.NET.
' Consider using a Lambda Expression instead.
// A Query Expression cannot be constructed for Concat() in F#.
// Consider using a Lambda Expression instead.
  • C#
  • VB.Net
  • F#
static void Sample_Concat_Lambda_Strings()
{
    string[] vegetables = { "Tomato", "Cucumber", "Carrot" };
    string[] fruits = { "Apples", "Grapes", "Banana" };

    var result = vegetables.Concat(fruits);

    Debug.WriteLine("Concatinating vegetables and fruits gives:");
    foreach (string piece in result)
        Debug.WriteLine(piece);
}
Output:
Concatinating vegetables and fruits gives:
Tomato
Cucumber
Carrot
Apples
Grapes
Banana
Private Shared Sub Sample_Concat_Lambda_Strings()
    Dim vegetables As String() = {"Tomato", "Cucumber", "Carrot"}
    Dim fruits As String() = {"Apples", "Grapes", "Banana"}

    Dim result = vegetables.Concat(fruits)

    Debug.WriteLine("Concatinating vegetables and fruits gives:")
    For Each piece As String In result
        Debug.WriteLine(piece)
    Next
End Sub
Output:
Concatinating vegetables and fruits gives:
Tomato
Cucumber
Carrot
Apples
Grapes
Banana
let Sample_Concat_Linq_Strings() =
    let vegetables = [|"Tomato"; "Cucumber"; "Carrot"|]
    let fruits = [|"Apples"; "Grapes"; "Banana"|]

    let result = vegetables.Concat(fruits)

    Debug.WriteLine(sprintf "Concatenating vegetables and fruits gives:")
    for piece in result do
        Debug.WriteLine(sprintf "%s" piece)
Output:
Concatenating vegetables and fruits gives:
Tomato
Cucumber
Carrot
Apples
Grapes
Banana

Share this sample on:

© 2023 - LINQSamples.com | Terms Of Service  -  Privacy Policy