baobao
10/8/2014 - 2:32 AM

C#ソート関数

C#ソート関数

class SortTest {
  
 void Start ()
 {
    List<Foo> a = new List<Foo> ();
    a.Add (new Foo (1));
    a.Add (new Foo (100));
    a.Add (new Foo (30));
    a.Add (new Foo (20));
    a.Add (new Foo (99));

		for (int i = 0; i < a.Count; i++) {
			Debug.LogError (a [i].a);
		}

			Debug.LogError ("===============");

			a.Sort ((x, y) => {
				int flg = 0;
				int xx = x.a;
				int yy = y.a;
				Debug.LogError ("xx : " + xx + " yy : " + yy);
				return 1;
			});

			for (int i = 0; i < a.Count; i++) {
				Debug.LogError (a [i].a);
			}
 }
  class Foo
		{
			public int a;

			public Foo (int a)
			{
				this.a = a;
			}
		}
}