Working with Data

Sorting

Method Name
Description
C# Query Expression Syntax

OrderBy

Sorts values in ascending order.

orderby

OrderByDescending

Sorts values in descending order.

orderby … descending

ThenBy

Performs a secondary sort in ascending order.

orderby …, …

ThenByDescending

Performs a secondary sort in descending order.

orderby …, … descending

Reverse

Reverses the order of the elements in a collection.

NA

string[] words = {"the", "quick", "brown", "fox", "jumps"};

IEnumerable<string> queryStx =
	from word in words
	orderby word.Length
	select word;

IEnumerable<string> methodStx = words.OrderBy(w => w.Length);

foreach (string str in queryStx)
	Console.Write(str + " ");

/* Output : the fox quick brown jumps */

Filtering

Method Name
Description
C# Query Expression Syntax

OfType

Selects values, depending on their ability to be cast to a specified type.

NA

Where

Selects values that are based on a predicate function.

where

Partitioning

Method names
Description

Skip

Skips elements up to a specified position in a sequence.

SkipWhile

Skips elements based on a predicate function until an element does not satisfy the condition.

Take

Takes elements up to a specified position in a sequence.

TakeWhile

Takes elements based on a predicate function until an element does not satisfy the condition.

Chunk

Splits the elements of a sequence into chunks of a specified maximum size.

Grouping

Method Name
Description
C# Query Expression Syntax

GroupBy

Groups elements that share a common attribute. Each group is represented by an IGrouping<TKey,TElement> object.

group … by -or- group … by … into …

ToLookup

Inserts elements into a Lookup<TKey,TElement> (a one-to-many dictionary) based on a key selector function.

NA

Last updated

Was this helpful?