Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
class Program
{
static void Main(string[] args)
{
List<Player> foo = new List<Player>
{
new Player(100, "Miku"),
new Player(350, "Ren"),
new Player(700, "Yukarin"),
new Player(3500, "IA")
};
var sortedByHp = foo.OrderBy(e => e.hp); //sort hp
var sortedByName = foo.OrderBy(e => e.name); //sort name
sortedByHp.ToList().ForEach(x => Console.WriteLine(x.hp)); //show
sortedByName.ToList().ForEach(x => Console.WriteLine(x.name)); //show
}
}
class Player
{
public int hp;
public string name;
public Player(int hp, string name)
{
this.hp = hp;
this.name = name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment