OrderBy operator

1. How to order a sequence?

 

            var customers = from c in Data.Customers

                            orderby c.Name

                            select c.Name;

 

 

public static OrderedSequence<TSource> OrderBy<TSource, TKey>(

    this IEnumerable<TSource> source,

    Func<TSource, TKey> keySelector);

 

public static OrderedSequence<TSource> OrderBy<TSource, TKey>(

    this IEnumerable<TSource> source,

    Func<TSource, TKey> keySelector,

    IComparer<TKey> comparer);

 

 

            var customers = Data.Customers

                                .OrderBy(c => c.Name)

                                .Select(c => c.Name);

 

            var customersDesc = from c in Data.Customers

                                orderby c.Name descending

                                select c.Name;

 

public static OrderedSequence<TSource> OrderByDescending<TSource, TKey>(

    this IEnumerable<TSource> source,

    Func<TSource, TKey> keySelector);

 

public static OrderedSequence<TSource> OrderByDescending<TSource, TKey>(

    this IEnumerable<TSource> source,

    Func<TSource, TKey> keySelector,

    IComparer<TKey> comparer);

 

 

            var customersDesc = Data.Customers

                    .OrderByDescending(c => c.Name)

                    .Select(c => c.Name);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s