How would I order this List alphabetically by name?

I was checking out this tutorial over here: Lists and Dictionaries - Unity Learn and following the example shown I understood perfectly how is the implementation of the Sort() function and the necessity of adding the IComparable interface to my class.

But there was a question that kept bugging me which was: in the same example used in that tutorial, how could I get the Sort() function to order my list alphabetically (with the name of the badguys) instead of using the “power” variable?? Since I can’t simply substract two strings to give me the int I need to return in the CompareTo function… THANKS IN ADVANCE!

Just edit the BadGuy.CompareTo code:

public CompareTo (BadGuy other) {
     if (other == null) return 1;
     return String.CompareTo (other.name);
}

If you want to keep the CompareTo code, you can use this code to sort:

badguys.Sort ((x, y) => x.name.CompareTo (y.name));