ThenBy operator

1. How to order a sequence by different keys?

Example 1:

 

 

            var customers = from c in Data.Customers

                            orderby c.Name, c.City

                            select c;

 

Output:

 

Frank – Seattle – USA

Frank – Sevastopol – USA

James – Dallas – USA

Marco – Torino – Italy

Paolo – Brescia – Italy

 

 

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

    this OrderedSequence<TSource> source,

    Func<TSource, TKey> keySelector);

 

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

    this OrderedSequence<TSource> source,

    Func<TSource, TKey> keySelector,

    IComparer<TKey> comparer);

 

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

    this OrderedSequence<TSource> source,

    Func<TSource, TKey> keySelector);

 

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

    this OrderedSequence<TSource> source,

    Func<TSource, TKey> keySelector,

    IComparer<TKey> comparer);

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