C#对象内部属性排序测试
构建对象:
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 (, );
SortGrid sg1 = new SortGrid (, );
SortGrid sg3 = new SortGrid (, ); 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#对象内部属性排序测试的更多相关文章
- java 对list中对象按属性排序
实体对象类 --略 排序类----实现Comparator接口,重写compare方法 package com.tang.list; import java.util.Comparator; publ ...
- List集合中的对象根据属性排序
集合类List存放的数据,默认是按照放入时的顺序存放的,比如依次放入A.B.C,则取得时候,则也是A.B.C的顺序,实际场景中,有时我们需要根据自定义的规则对List中的元素进行排序,该如何实现呢?看 ...
- 对象内部属性[[Class]]
1.概述 所有的typeof返回值为‘object’的对象都包含一个内部属性[[Class]],我们将它可以看做内部的分类,而非传统面向对象意义的分类.这个属性无法直接访问,一般通过Object.pr ...
- JS中对象按属性排序(冒泡排序)
在实际工作经常会出现这样一个问题:后台返回一个数组中有i个json数据,需要我们根据json中某一项进行数组的排序. 例如返回的数据结构大概是这样: { result:[ {id:,name:'中国银 ...
- JsonPropertyOrder无法为DTO对象进行属性排序
在项目中,遇到一个问题,无论怎么设置JsonPropertyOrder,都无法正确实现排序功能,问题代码如下: @JsonPropertyOrder(value={"courseId&quo ...
- java list中的对象,按对象某属性排序
1:对象类 需要 实现: public class TreeNode extends BaseBean implements Comparable <TreeNode> { private ...
- java根据list中的对象某个属性排序
1. Collections.sort public class Test { public static void main(String[] args) throws Exception { Ci ...
- Java对象根据属性排序
参考:https://blog.csdn.net/wangtaocsdn/article/details/71500500
- JavaScript | 对象与属性
———————————————————————————————————————————— 对象:JavaScript是基于原型的语言,没有Class,所以将函数作为类 - - - - - - - - ...
随机推荐
- IIS上配置单页面404
问题 因为我们的应用是单页客户端应用,当用户在浏览器直接访问http://www.xxx.com/user时,刷新页面的时候,会返回404错误. 问题原因 服务端URL匹配不到相应的路由资源 解决方案 ...
- tiny4412 --uboot移植(1)
开发环境:win10 64位 + VMware12 + Ubuntu14.04 32位 工具链:linaro提供的gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-g ...
- est-framework框架的基本组件
rest-framework框架的基本组件 快速实例 Quickstart 序列化 创建一个序列化类 简单使用 开发我们的Web API的第一件事是为我们的Web API提供一种将代码片段实例序列 ...
- springboot 使用JPA自动生成Entity实体类的方法
1. 2. 3.添加数据库 4. 5. 6. 7.点击OK完成. 8.去掉红色波浪线方法. 9.配置数据源 完成!
- [翻译]高并发框架 LMAX Disruptor 介绍
原文地址:Concurrency with LMAX Disruptor – An Introduction 译者序 前些天在并发编程网,看到了关于 Disruptor 的介绍.感觉此框架惊为天人,值 ...
- redis在游戏服务器中的使用初探(四) redis应用
文章系列先介绍环境搭建 介绍redis操作和代码编写运行 这是典型的实战工程过程.那么我们为何要使用redis而不是常规的数据库比如 mysql呢? 因为KV内存数据库最大的优势所有数据全部存储在内 ...
- java多线程系列9 高级同步工具(3) CyclicBarrier
CyclicBarrier 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point) 然后一再执行 public class CyclicBar ...
- 在centos7上使用最简单的方法把php脚本做成服务,随开机启动运行
1.准备文件:coffeetest.service # copy to /usr/lib/systemd/system # systemctl enable coffeetest.service [U ...
- ActiveMQ_4SpringBoot整合
SpringBoot实现 引入jar包 <dependency> <groupId>org.springframework.boot</groupId> ...
- springsecurity 源码解读之 SecurityContext
在springsecurity 中,我们一般可以通过代码: SecurityContext securityContext = SecurityContextHolder.getContext(); ...