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

SkipWhile

Lambda Query

SkipWhile: Skips elements in a collection while specified condition is met.

SkipWhile: Skips elements in a collection while specified condition is met.

This Lambda Expression sample skips words in array, as long as word has length of 3 characters.

This Lambda Expression sample skips words in array, as long as word has length of 3 characters.

  • C#
  • VB.Net
  • F#
// A Query Expression cannot be constructed for SkipWhile() in C#.
// Consider using a Lambda Expression instead.
' A Query Expression cannot be constructed for SkipWhile() in VB.NET.
' Consider using a Lambda Expression instead.
let Sample_SkipWhile_Linq() =
    let words = [| "one"; "two"; "three"; "four"; "five"; "six" |]

    let result = query {
        for w in words do
        skipWhile (w.Length = 3)
    }

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

    var result = words.SkipWhile(w => w.Length == 3);

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

    Dim result = words.SkipWhile(Function(w) w.Length = 3)

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

    let result = words.SkipWhile(fun w -> w.Length = 3);

    Debug.WriteLine(sprintf "Skips words while the condition is met:")
    for word in result do
        Debug.WriteLine(sprintf "%s" word)
Output:
Skips words while the condition is met:
three
four
five
six

Share this sample on:

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