Queryable.OrderDescending Method

Definition

Overloads

OrderDescending<T>(IQueryable<T>, IComparer<T>)

Sorts the elements of a sequence in descending order.

OrderDescending<T>(IQueryable<T>)

Sorts the elements of a sequence in descending order.

OrderDescending<T>(IQueryable<T>, IComparer<T>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

Sorts the elements of a sequence in descending order.

C#
public static System.Linq.IOrderedQueryable<T> OrderDescending<T>(this System.Linq.IQueryable<T> source, System.Collections.Generic.IComparer<T> comparer);

Type Parameters

T

The type of the elements of source.

Parameters

source
IQueryable<T>

A sequence of values to order.

comparer
IComparer<T>

An IComparer<T> to compare elements.

Returns

An IOrderedEnumerable<TElement> whose elements are sorted.

Exceptions

source is null.

Remarks

This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

The Order<T>(IQueryable<T>) method generates a MethodCallExpression that represents calling Order<T>(IEnumerable<T>) itself as a constructed generic method. It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter. The result of calling CreateQuery<TElement>(Expression) is cast to type IOrderedQueryable<T> and returned.

The query behavior that occurs as a result of executing an expression tree that represents calling Order<T>(IEnumerable<T>) depends on the implementation of the source parameter. The expected behavior is that it sorts the elements of source by itself.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10

OrderDescending<T>(IQueryable<T>)

Source:
Queryable.cs
Source:
Queryable.cs
Source:
Queryable.cs

Sorts the elements of a sequence in descending order.

C#
public static System.Linq.IOrderedQueryable<T> OrderDescending<T>(this System.Linq.IQueryable<T> source);

Type Parameters

T

The type of the elements of source.

Parameters

source
IQueryable<T>

A sequence of values to order.

Returns

An IOrderedEnumerable<TElement> whose elements are sorted.

Exceptions

source is null.

Remarks

This method has at least one parameter of type Expression<TDelegate> whose type argument is one of the Func<T,TResult> types. For these parameters, you can pass in a lambda expression and it will be compiled to an Expression<TDelegate>.

The Order<T>(IQueryable<T>) method generates a MethodCallExpression that represents calling Order<T>(IEnumerable<T>) itself as a constructed generic method. It then passes the MethodCallExpression to the CreateQuery<TElement>(Expression) method of the IQueryProvider represented by the Provider property of the source parameter. The result of calling CreateQuery<TElement>(Expression) is cast to type IOrderedQueryable<T> and returned.

The query behavior that occurs as a result of executing an expression tree that represents calling Order<T>(IEnumerable<T>) depends on the implementation of the source parameter. The expected behavior is that it sorts the elements of source by itself.

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8, 9, 10