I have a list of strings where I need to sort it by the ending substring. For example, assume we have these strings in the list:
Get_USER_By_ID
Get_Product_By_Name
Get_Product_By_ID
Get_Location_By_Name
...
I Need to sort it so that all the functions matching the same By_ are after each other
I could loop over the list, and create many new lists, and if the string contains a specific string (i.e. By_ID), I add it to its related List.
I want to sort them in the same list (same as if I say sort ascending or descending for instance) rather than creating many new lists (in my case I have to create 9 new lists)
names.OrderBy(name => name.Split(new[] {"By_"}, StringSplitOptions.None).Last())ToList()to the call suggested by @Fabio