Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Trying to create a linq OrderBy alias

Trying to create a linq OrderBy alias

Trying to create a linq OrderBy alias

I use the following to sort text containing strings and integers naturally



.OrderBy(x => x.some_class_property_string, new OrdinalStringComparer(true))) 

I have been trying to create an alias (I hope I am using the correct terminology) so I can centralize and end up doing the following instead

Change to


.OrderByNaturalSorting(x => x.some_class_property_string)) 

Alias code


public static IOrderedEnumerable<TSource> OrderByNaturalSorting<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
    return source.OrderBy(keySelector, new OrdinalStringComparer(true));

I am pretty much at the point of giving up and just copying and pasting "new OrdinalStringComparer(true)" everywhere i need it as I have no idea where to go from here. I have tried changing TSource to string, but that didnt work. Reading an MSDN page on this didn't help. You all are my last resort.

thanks for you time.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close