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

Skip

Lambda Query

Skip: Skips specified number of elements in a collection.

Skip: Skips specified number of elements in a collection.

This Lambda Expression sample skips first 4 words in array.

This Lambda Expression sample skips first 4 words in array.

  • C#
  • VB.Net
  • F#
// A Query Expression cannot be constructed for Skip() in C#.
// Consider using a Lambda Expression instead.
Private Shared Sub Sample_Skip_Linq()
    Dim words As String() = {"one", "two", "three", "four", "five", "six"}

    Dim result = From n In words Skip 4

    Debug.WriteLine("Skips the first 4 words:")
    For Each number As String In result
        Debug.WriteLine(number)
    Next
End Sub
Output:
Skips the first 4 words:
five
six
let Sample_Skip_Linq() =
    let words = [| "one"; "two"; "three"; "four"; "five"; "six" |]

    let result = query {
        for w in words do
        skip 4
    }

    Debug.WriteLine(sprintf "Skips the first 4 words:")
    for word in result do
        Debug.WriteLine(sprintf "%s" word)
Output:
Skips the first 4 words:
five
six
  • C#
  • VB.Net
  • F#
static void Sample_Skip_Lambda()
{
    string[] words = { "one", "two", "three", "four", "five", "six" };

    var result = words.Skip(4);

    Debug.WriteLine("Skips the first 4 words:");
    foreach (string word in result)
        Debug.WriteLine(word);
}
Output:
Skips the first 4 words:
five
six
Private Shared Sub Sample_Skip_Lambda()
    Dim words As String() = {"one", "two", "three", "four", "five", "six"}

    Dim result = words.Skip(4)

    Debug.WriteLine("Skips the first 4 words:")
    For Each word As String In result
        Debug.WriteLine(word)
    Next
End Sub
Output:
Skips the first 4 words:
five
six
let Sample_Skip_Lambda() =
    let words = [| "one"; "two"; "three"; "four"; "five"; "six" |]

    let result = words.Skip(4);

    Debug.WriteLine(sprintf "Skips the first 4 words:")
    for word in result do
        Debug.WriteLine(sprintf "%s" word)
Output:
Skips the first 4 words:
five
six

Share this sample on:

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