C#对象内部属性排序测试
2016-10-18 10:01
471 查看
构建对象:
编辑排序方法:
调用方法:
运行结果:
class SortGrid { int indexI; int indexJ; public SortGrid(int x, int y) { indexI = x; indexJ = y; } public int IndexI { get { return indexI; } set { indexI = value; } } public int IndexJ { get { return indexJ; } set { indexJ = value; } } }
编辑排序方法:
//排序测试 void SortTest () { Debug.Log ("C#对象内部属性排序测试:"); SortGrid sg2 = new SortGrid (5, 4); SortGrid sg1 = new SortGrid (1, 6); SortGrid sg3 = new SortGrid (3, 2); List<SortGrid> lsg = new List<SortGrid> (); lsg.Add (sg1); lsg.Add (sg2); lsg.Add (sg3); lsg.Sort (delegate(SortGrid x, SortGrid y) { return x.IndexI.CompareTo(y.IndexI); }); foreach (var item in lsg) { Debug.Log("indexI:" + item.IndexI); } lsg.Sort (delegate(SortGrid x, SortGrid y) { return y.IndexI.CompareTo(x.IndexI); }); foreach (var item in lsg) { Debug.Log("indexI:" + item.IndexI); } }
调用方法:
// Use this for initialization void Start () { SortTest (); }
运行结果:
相关文章推荐
- C#中List实现按照对象属性排序
- C#List<>能按照List中的对象某个属性排序
- C#中List实现按照对象属性排序
- Win8 C# 对象排序---通过某个属性
- C# List按照对象属性进行排序
- C#对List 的对象的属性进行排序
- C#中对List<Object>泛型集合,根据对象的某一属性进行升序排序
- C# 3.0新特性之Automatic Properties(自动属性)、Object Initializers(对象初始化器)、Collection Initializers(集合初始化器)和Extension Methods(扩展方法)
- C#基础之数组 (排序,对象大小比较)
- javascript调试测试,利用vs2008:智能对象类型感知,方法及属性提示;立即窗口调试等
- C#.net的内部对象
- 建立可对任意属性排序的对象集合
- 在C#如何遍历一个对象的所有属性
- C#对象数组排序方法
- C#的新特性:自动属性,对象初始化器,和集合初始化器(转载)
- Java集合对象排序测试
- 复习:C#3.0面向对象测试开发包
- 步步为营VS 2008 + .NET 3.5(3) - C# 3.0新特性之Automatic Properties(自动属性)、Object Initializers(对象初始化器)、Collection Initializers(集合初始化器)和Extension Methods(扩展方法)
- 复习:C#3.0面向对象测试开发包
- 对象数组根据某属性列的灵活排序