Skip to content

Instantly share code, notes, and snippets.

@Collonville
Created December 11, 2015 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Collonville/66a0837cc6e1ac878437 to your computer and use it in GitHub Desktop.
Save Collonville/66a0837cc6e1ac878437 to your computer and use it in GitHub Desktop.
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